Re: [Bug] git stash generates a different diff then other commands (diff, add, etc) resulting in merge conflicts!
- From
Phil Hord <phil.hord@gmail.com>
- Date
- Aug 16, 2013, 00:05 UTC
- Message-ID
- <CABURp0qFnvW4X9MLhB=Q45S6xmV1HJ1-8NGRD7UyOLrLVxapvQ@mail.gmail.com>
- In-Reply-To
- <5209C4CD.8040607@gmail.com>
On Tue, Aug 13, 2013 at 1:31 AM, Luke San Antonio <lukesanantonio@gmail.com> wrote:
Show 6 quoted lines
> > So I found an isolated case, it's very strange... > > Here's a script! > >
<deleted>
Thanks for that. It was hard to read, but it demonstrates the problem well.
Show 8 quoted lines
> ... Copy and paste that into a terminal and you should have a recreated > version of my repository there! Now that the file is partly stashed and > partly in the index, check out the difference in diffs: > > try: > git diff --staged > then try: > git stash show -p
This one is pretty sneaky. It is not limited to git-stash. I can demonstrate the problem now using 'git merge-file'.
But I can only make this problem show itself when: 1. The collisions are separated by just one line of common code, and 2. One of the lines of common code is duplicated in one of the collisions, and 3. The first two lines of the file are duplicated, and 4. One of the first two lines is deleted on one side but not the other.
I have managed to boil the test down to this script:
#-----------------------------
cat >base <<base
1 duplicate
1 duplicate
3 unchanged
4 will change
5 gets deleted
7 duplicated
8 will change
base cat >left <<left
1 duplicate
1 duplicate
3 unchanged
4 changed
7 duplicated
6 new line
7 duplicated
8 changed
leftsed -e 1d left > right
git merge-file -p left base right
#-----------------------------
The result looks like this, showing the duplicate "collision":
1 duplicate 3 unchanged 4 changed <<<<<<< left 7 duplicated 6 new line 7 duplicated ======= 7 duplicated 6 new line 7 duplicated >>>>>>> right 8 changed
But it should look like this instead:
1 duplicate 3 unchanged 4 changed 7 duplicated 6 new line 7 duplicated 8 changed
A similar (but different) stupidity shows up if you remove line "3" from all three files.
I tested this in 1.6.5 and the same thing occurs there, so this is NOT recent regression.
Phil