我是靠谱客的博主 英俊金毛,这篇文章主要介绍Squash Commits with Git,现在分享给大家,希望可以做个参考。

复制代码
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:

复制代码
1
git 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
17
pick 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
17
pick 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:

复制代码
1
git 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部