我使用git flow创建了两个git flow feature start <feature name>
分支。我不记得我是否完成了
git flow feature finish
,A
合并到分支B
,删除分支A
,然后从分支git flow feature finish
运行B
,或B
合并到develop
git flow feature finish
,然后将分支A
合并到develop
git merge
,解决合并冲突,以及然后使用A
git branch -d <branch name>
醇>
使用git reflog
分支A
的最后一个跟踪,我可以在系列中找到e553bf0
:
e553bf0 HEAD@{40}: checkout: moving from feature/a to develop
6b30050 HEAD@{41}: checkout: moving from develop to feature/a
e553bf0 HEAD@{42}: checkout: moving from feature/a to develop
6b30050 HEAD@{43}: checkout: moving from develop to feature/a
e553bf0 HEAD@{44}: commit (merge): resolved merge conflicts
7a0ad6b HEAD@{45}: checkout: moving from feature/a to develop
6b30050 HEAD@{46}: checkout: moving from develop to feature/a
7a0ad6b HEAD@{47}: merge feature/b: Merge made by the 'recursive' strategy.
921ae46 HEAD@{48}: checkout: moving from feature/b to develop
此外,git log
显示
commit e553bf07272ab2b1975917b736b37127636c0db1
Merge: 7a0ad6b 6b30050
Author: Eric Baldwin <address-here>
Date: Thu Jul 25 14:58:49 2013 -0400
resolved merge conflicts
commit 7a0ad6b2277c0c0a7599193829f68517ac708ca2
Merge: 921ae46 02558b6
Author: Eric Baldwin <address-here>
Date: Thu Jul 25 14:03:56 2013 -0400
Merge branch 'feature/b' into develop
这两个功能的代码目前都在develop
,但我不知道合并发生的顺序。有人可以告诉我基于历史记录发生了哪三种情景?
编辑:
git log --oneline --graph develop
的输出:
* 2ebb938 misc
* 69f95f6 Merge 'feature/x' into 'develop' merge conflicts
|\
| * 8b9b275 Merge 'develop' with feature/x; minor merge tweaks
| * eb89630 misc
| * 54884d2 misc
| * 76f02bb Merge branch 'develop' into feature/x
| |\
| * | d06d673 misc
| * | 0ba5235 misc
* | | 5489590 misc
* | | a215bd2 misc
* | | 4aacaa7 misc
* | | e553bf0 resolved merge conflicts
|\ \ \
| * | | 6b30050 fixed test db error
| * | | 64909f9 Merge branch 'develop' into feature/a
| |\ \ \
| * \ \ \ e7319e1 Merge branch 'develop' into feature/a
| |\ \ \ \
| * | | | | 410786b misc
| * | | | | 67267f3 misc
| * | | | | ae4b800 misc
| * | | | | 9e281eb Merge branch 'develop' into feature/a
| |\ \ \ \ \
| * | | | | | f8fa2ec misc
* | | | | | | 7a0ad6b Merge branch 'feature/b
|\ \ \ \ \ \ \
| * | | | | | | 02558b6 ready to merge
| * | | | | | | cc07f79 Merge branch 'develop' into feature/b
| |\ \ \ \ \ \ \
| | | |_|_|/ / /
| | |/| | | | |
| * | | | | | | 4b6610f misc
| * | | | | | | 25e509b Merge branch 'develop' into feature/b
| |\ \ \ \ \ \ \
| | | |_|_|/ / /
| | |/| | | | |
| * | | | | | | df5640d merged with develop
答案 0 :(得分:5)
看起来您已将A
合并到7a0ad6b
的第一个开发中。不太确定之后发生了什么。根据您的git log
输出,看起来您可能已将B
合并到e553bf0
开发:
* | | e553bf0 resolved merge conflicts
|\ \ \
| * | | 6b30050 fixed test db error
| * | | 64909f9 Merge branch 'develop' into feature/b
但根据您的reflog,6b30050
实际上是feature/a
:
6b30050 HEAD@{43}: checkout: moving from develop to feature/a
e553bf0 HEAD@{44}: commit (merge): resolved merge conflicts
当您将输出复制到问题中时,您不会意外地将分支名称混淆,是吗?
仅基于您的原始reflog
,看起来您首先将分支B
合并到develop
,然后尝试合并分支A
,解决冲突,然后提交:
# Checkout develop
e553bf0 HEAD@{42}: checkout: moving from feature/a to develop
# Checkout branch A
6b30050 HEAD@{43}: checkout: moving from develop to feature/a
# Merge branch A? Resolve conflicts and commit
e553bf0 HEAD@{44}: commit (merge): resolved merge conflicts
# Checkout develop
7a0ad6b HEAD@{45}: checkout: moving from feature/a to develop
# Checkout branch A
6b30050 HEAD@{46}: checkout: moving from develop to feature/a
# Merge branch B into develop
7a0ad6b HEAD@{47}: merge feature/b: Merge made by the 'recursive' strategy.
# Move from branch B to develop (i.e. checkout commit 921ae46)
921ae46 HEAD@{48}: checkout: moving from feature/b to develop
当您确定哪个合并是哪个时,您应该能够使用
查看分支的日志git log --oneline --graph <sha of merge into develop>^2
这意味着显示合并提交的第二个父级的历史记录,如果您使用git flow,它将是功能分支的提示。
如果有帮助,您还可以在用户develop
文件中使用此别名查看.gitconfig
分支的历史记录,其中包含创作日期和提交日期:
[alias]
datelog = log --format=\"%C(yellow)%h%C(reset) %C(cyan dim)%ad %C(red bold)%cd %C(reset)%s\" --graph
它将首先以蓝色显示创作日期,然后以红色显示提交日期。使用提交日期,您可能能够确定分支A
或B
是否已合并到开发中。您还可以使用git log --format=fuller
获取创作日期和提交日期。
最后,你知道如何rebase
吗?您可以使用develop
来同步而不是rebase
,通过merge
同步/合并提交来避免污染您的分支历史记录:
# From feature branch X, sync with develop
git rebase develop
# Switch to develop and merge
# (either fast-forward or merge commit, your choice)
git checkout develop
git merge --no-ff X