1
2
3
4
5# switch to master branch git checkout master # ensure our master is up to date git pull remoteRepoName master
With the master branch up to date, we'll use git rebase to consolidate:
1git rebase -i master
That command will show a list of each commit, as such:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17pick fb554f5 This is commit 1 pick 2bd1903 This is commit 2 pick d987ebf This is commit 3 # Rebase 9cbc329..d987ebf onto 9cbc329 # # 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 # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
Edit the summary shown to you by the rebase command, leaving the commit you want to be the main commit as "pick" and changing all subsequent "pick" commands as "squash":
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17pick fb554f5 This is commit 1 squash 2bd1903 This is commit 2 squash d987ebf This is commit 3 # Rebase 9cbc329..d987ebf onto 9cbc329 # # 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 # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
Write/quit past the editor twice (the second screen would allow you to change the commit message, though I like to keep it the same). At this point, your commits are squashed into one. Run the following command to force a push of the new, consolidated commit:
1git push -f
This forced push updates the source repository and our commits have become one. If you had already submitted a pull request at GitHub, the pull request would now show only one commit! With one consolidated commit, code review becomes much, much easier!
最后
以上就是英俊金毛最近收集整理的关于Squash Commits with Git的全部内容,更多相关Squash内容请搜索靠谱客的其他文章。
发表评论 取消回复