8

我使用git flow创建了两个带有git flow feature start <feature name>. 我不记得我是否完成了

  1. git flow feature finish在两个分支上使用,
  2. 将分支合并A到分支B,删除分支A,然后git flow feature finish从分支运行B,或
  3. 将分支合并Bdevelopwith 中git flow feature finish,然后将分支合并Adevelopwith 中git merge,解决合并冲突,然后删除分支Awithgit branch -d <branch name>

使用我能找到git reflog的最后一个分支跟踪是在系列中:Ae553bf0

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
4

1 回答 1

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

仅根据您的原始文件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

它将首先以蓝色显示创作日期,然后以红色显示提交日期。使用提交日期,您可能能够首先确定分支AB合并到开发中。您还可以使用git log --format=fuller.

支持 rebase 而不是合并(通常)

最后,你知道怎么做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
于 2013-08-05T02:47:30.617 回答