我听说过关于Git的"合并泡沫".我对Git非常熟悉,但不认为自己是专家.我听说过一些关于合并泡沫的负面消息; 什么是Git中的"合并泡沫",它有什么问题,我该如何避免呢?
Pet*_*hie 43
一个合并的泡沫是一个"平凡的合并"在Git中,并不需要任何冲突得到解决.当您使用该--graph选项时,会在显示合并的日志中出现气泡.例如,如果你跑了,git log --graph你可能会看到这样的事情:
| |
* | commit d79f3c4e129356b055c659ee5be28081c1f38aa1
|\ \ Merge: 09bf1ed 4ef9a23
| | | Author: Peter <peter@example.com>
| | | Date: Wed Sep 17 17:21:07 2014 -0400
| | |
| | | Merge branch 'master' of http://fictitiousrepo.visualstudio.com/DefaultCollection/_git/fictitiousproject
| | |
| * | commit 4ef9a2387f0d4db39a6cab8ff8f531815935c305
| | | Author: Andrew <andrew@example>
| | | Date: Tue Sep 16 11:54:14 2014 -0500
| | |
| | | updated changelog
| | |
* | | commit 09bf1ed0125d77c26b5760939c125998bb046e9a
|/ / Author: Peter <peter@example.com>
| | Date: Wed Sep 17 17:20:30 2014 -0400
| |
| | fixed some bugs
Run Code Online (Sandbox Code Playgroud)
线条"凸出"的地方是"合并泡沫".这似乎无害; 但许多人认为它的可读性远远低于可能发生的可读性,如下所示:
|
* commit 09bf1ed0125d77c26b5760939c125998bb046e9a
| Author: Peter <peter@example.com>
| Date: Wed Sep 17 17:20:30 2014 -0400
|
| fixed some bugs
|
* commit 4ef9a2387f0d4db39a6cab8ff8f531815935c305
| Author: Andrew <andrew@example>
| Date: Tue Sep 16 11:54:14 2014 -0500
|
| updated changelog
|
Run Code Online (Sandbox Code Playgroud)
...因为没有真正需要合并.
当通过自动合并拉取请求来接受拉取请求时,通常会发生这种情况.有时这是由于"Merge Pull Request"按钮在Github上的工作方式.
为了避免合并气泡与拉取请求,一种策略是手动合并.例如:
git checkout master
git remote add remoteorigin git://remotegithost.com/remotegitrepo/remotegitproject
git fetch remoteorigin
git merge remoteorigin/remoteprojectbranch
git push origin master
Run Code Online (Sandbox Code Playgroud)
要从拉取请求中删除最近提交的合并气泡(当您没有推送时),一种策略是首先存储当前的更改,将头重置为泡沫前的提交,使用rebase拉动,然后推送.例如:
git stash save
git reset --hard HEAD~1
git pull --rebase
git push origin HEAD
Run Code Online (Sandbox Code Playgroud)
参考:http: //adammonsen.com/post/1172
| 归档时间: |
|
| 查看次数: |
5379 次 |
| 最近记录: |