git rebase --interactive 원하는 명령입니다.
예:
현재 상태는 다음과 같습니다.
bernt@le3180:~/src/stackoverflow/reordering_of_commits
$ git status
On branch master
nothing to commit, working tree clean
bernt@le3180:~/src/stackoverflow/reordering_of_commits
$ git log --oneline
a6e3c6a (HEAD -> master) Fourth commit
9a24b81 Third commit
7bdfb68 Second commit
186d1e0 First commit
커밋 9a24b81(세 번째 커밋)과 7bdfb68(두 번째 커밋) 순서를 바꾸고 싶습니다 . 이렇게하려면 먼저 변경하려는 첫 번째 커밋 전에 커밋을 찾습니다 . 이것은 커밋 186d1e0(첫 번째 커밋)입니다.
실행할 명령은 git rebase --interactive COMMIT-BEFORE-FIRST-COMMIT-WE-WANT-TO-CHANGE입니다.이 경우 :
bernt@le3180:~/src/stackoverflow/reordering_of_commits
$ git rebase --interactive 186d1e0
그러면 다음 내용이 포함 된 파일이 기본 편집기에서 열립니다.
pick 7bdfb68 Second commit
pick 9a24b81 Third commit
pick a6e3c6a Fourth commit
# Rebase 186d1e0..a6e3c6a onto 186d1e0 (3 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
파일의 커밋 순서는 git log에 사용되는 순서와 반대입니다. git log에서 가장 최근 커밋은 맨 위에 있습니다. 이 파일에서 가장 최근 커밋은 맨 아래에 있습니다.
파일 하단의 주석에서 설명하는 것처럼 커밋을 스쿼시, 삭제 및 재정렬하는 등 제가 할 수있는 다양한 작업이 있습니다. 커밋 순서를 변경하려면 다음과 같이 파일을 편집합니다 (하단 주석은 표시되지 않음).
pick 9a24b81 Third commit
pick 7bdfb68 Second commit
pick a6e3c6a Fourth commit
pick각 라인 수단 "사용 (예 포함)이 커밋"내가하고 REBASE 명령과 임시 파일 저장 편집기를 종료 할 때, 자식이 명령을 실행하고 저장소와 작업 디렉토리를 업데이트의 시작 명령
$ git rebase --interactive 186d1e0
Successfully rebased and updated refs/heads/master.
bernt@le3180:~/src/stackoverflow/reordering_of_commits
$ git log --oneline
ba48fc9 (HEAD -> master) Fourth commit
119639c Second commit
9716581 Third commit
186d1e0 First commit
재 작성된 커밋 기록을 확인합니다.
연결: