12

When do different git status unmerged states occur, like added by us, added by them or both deleted?

I've tried to reproduce the latter by performing a merge where a file has been deleted in the current and merged-from branch, but I was not able to create this status.

Nathan Long
  • 113,812
  • 91
  • 316
  • 418
mklhmnn
  • 3,930
  • 2
  • 14
  • 8

1 Answers1

18

You can get all three by renaming a file differently in each branch.

git init
touch foo
git add foo
git commit -m 'initial commit'
git checkout -b tmp
git mv foo X
git commit -m 'rename to X'
git checkout -
git mv foo Y
git commit -m 'rename to Y'
git merge tmp

Now you have all three states.

$ git status
# On branch master
# Unmerged paths:
#   (use "git add/rm ..." as appropriate to mark resolution)
#
#       added by them:      X
#       added by us:        Y
#       both deleted:       foo
#
no changes added to commit (use "git add" and/or "git commit -a")
Mark Lodato
  • 41,133
  • 5
  • 39
  • 31
  • Nice demo. This helped me see what us vs them means. If I'm in branch A and I'm merging in branch B, branch A is "us" and branch B is "them". – Nathan Long Nov 21 '11 at 16:24
  • 5
    Also - your example taught me `git checkout -`, which is like `cd -`; it means "checkout the branch I was on before switching to this one." For anyone else finding this, it only toggles between two branches; it doesn't maintain a history. – Nathan Long Nov 21 '11 at 16:25
  • 2
    As of Git 1.9.3, this example does not appear to work anymore: no merge conflict are generated. – Pol Dec 02 '14 at 22:09
  • 1
    Ah, thanks for pointing this out. [t/t7060-wtstatus.sh](https://github.com/git/git/blob/master/t/t7060-wtstatus.sh) in git.git has all of the cases. They're hard to decipher so I'll try to update my answer whenever I get some free time. – Mark Lodato Dec 04 '14 at 15:39
  • I can confirm this on git 2.7.4: no conflict. – But I do have a “added by us” somewhere else... Still not sure how “adding” can be in conflict... – Robert Siemer Dec 27 '16 at 17:30