简体   繁体   English

如何将两个git commit合并为一个?

[英]how to merge two git commits into one?

i have made two commits while in fact one commit is enough, the reason that i make two commits is because i forget to add one file after i make the first commit, so i add it and make another commit, after that i found that i find i have made two commit with the same comment, so how to merge these two commits into one? 我已经进行了两次提交,而实际上一次提交就足够了,我进行两次提交的原因是因为我忘记在进行第一次提交之后添加一个文件,所以我添加了它并进行了另一次提交,之后我发现我发现我已经用相同的注释进行了两次提交,那么如何将这两个提交合并为一个?

* 3e381e7 - (HEAD, master) now i have add load script which can open many pages automatically at one time (4 seconds ago) 
* 2d97025 - now i have add load script which can open many pages automatically at one time (21 seconds ago) 

how to merge commits 3e381e7 and 2d97025 so that there is only one commit log? 如何合并提交3e381e7和2d97025,以便只有一个提交日志?

Interactive rebase is your friend : 交互式基地是您的朋友:

git rebase -i

You can also do a git reset --soft followed by a git commit --amend but rebasing is the easiest way. 您也可以先执行git reset --soft然后执行git commit --amendgit reset --soft是最简单的方法。

Joining two commits into one is called "squashing". 将两个提交合并为一个称为“压缩”。 Do an interactive rebase, 进行互动式变基,

git rebase -i HEAD~3

and then in the text editor that opens, change the line with the 2d97025 to start with the word 'squash', then safe the file and exit the editor. 然后在打开的文本编辑器中,将2d97025的行更改为以'squash'开头,然后保护文件并退出编辑器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM