Pergunta

I used git flow to create two branches with git flow feature start <feature name>. I don't remember whether I finished by

  1. Using git flow feature finish on both branches,
  2. Merging branch A into branch B, deleted branch A, and then running git flow feature finish from branch B, or
  3. Merging branch B into develop with git flow feature finish and then merging branch A into develop with git merge, resolving the merge conflicts, and then deleting branch A with git branch -d <branch name>

Using git reflog the last trace of branch A I can find is e553bf0 in the series:

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

Also, git log shows

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

The code from both features is currently in develop, but I don't know in order the merges happened. Can someone tell me which of the three scenarios occurred based on the history?

Edit:

Output from 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
Foi útil?

Solução

Looks like you merged branch A into develop first at 7a0ad6b. Not quite sure what happened after that. According to your git log output, it looks like you might have merged B into develop at e553bf0:

* | |   e553bf0 resolved merge conflicts
|\ \ \  
| * | | 6b30050 fixed test db error
| * | |   64909f9 Merge branch 'develop' into feature/b

But according to your reflog, 6b30050 is actually feature/a:

6b30050 HEAD@{43}: checkout: moving from develop to feature/a
e553bf0 HEAD@{44}: commit (merge): resolved merge conflicts

You didn't accidentally get the branch names mixed up when you were copying the output into your question, did you?

Looking at just the reflog

Based on your original reflog alone, it looks like you merged branch B into develop first, then tried to merge branch A, resolved conflicts, then committed:

# 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

Viewing the history of the merged branch

When you figure out which merge is which, you should be able to view the log of the branch by using

git log --oneline --graph <sha of merge into develop>^2

which means show the history of the 2nd parent of the merge commit, which will be the tip of the feature branch if you're using git flow.

If it helps, you can also view the history of the develop branch with both the authored date and commit-date using this alias in your user .gitconfig file:

[alias]
    datelog = log --format=\"%C(yellow)%h%C(reset) %C(cyan dim)%ad %C(red bold)%cd %C(reset)%s\" --graph

It will show you the authored date first in blue, then the commit-date in red. Using the commit-date, you might be able to figure out if branch A or B was merged into develop first. You can also get both authored and commit-dates using git log --format=fuller.

Favor rebase over merge (usually)

Finally, do you know how to rebase? You can avoid polluting your branch histories with sync/merge commits with develop by using rebase to sync instead of 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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top