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 8, 2013, 20:54 UTC
- Message-ID
- <CABURp0oATJ58POmgYLjSmy-y84LTjkP0PTh4=3M-vc04_AoMdg@mail.gmail.com>
- In-Reply-To
- <CAP+CFTZWzoAg=ni6t1aif-85y6W4-2JUT4wooapTvD0oGH+HRw@mail.gmail.com>
On Thu, Aug 8, 2013 at 3:07 AM, Luke San Antonio <lukesanantonio@gmail.com> wrote:
Show 12 quoted lines
> > Hi, my name's Luke! > > Today, I had a problem merging a stash after immediately creating it. > This is exactly what I did! > > git stash save --keep-index > git stash pop > > And BAM! Merge conflict! This was especially weird because my file had > this in it (taken directly from my code!) >
Luke,
I think the issue is that your working directory receives your cached file when you say 'git stash --keep-index'. When you restore the stash, your previous working directory now conflicts with your new working directory, but neither is the same as HEAD.
Here's a test script to demonstrate the issue, I think. Did I get this right, Luke?
# cd /tmp && rm -rf foo git init foo && cd foo echo "foo" > bar && git add bar && git commit -mfoo echo "bar" > bar && git add bar echo "baz" > bar echo "Before stash bar: $(cat bar)" git stash --keep-index echo "After stash bar: $(cat bar)" git stash apply
The output looks like this:
$ git init foo && cd foo Initialized empty Git repository in /tmp/foo/.git/ $ git commit --allow-empty -mInitialCommit [master (root-commit) b5ecc7e] InitialCommit $ echo "Bar" > bar && git add bar && git commit -mBar [master 16d708b] Bar 1 file changed, 1 insertion(+) create mode 100644 bar $ echo "bar" > bar && git add bar $ echo "baz" > bar $ echo "Before stash bar: $(cat bar)" Before stash bar: baz $ git stash --keep-index Saved working directory and index state WIP on master: 16d708b Bar HEAD is now at 16d708b Bar $ echo "After stash bar: $(cat bar)" After stash bar: bar $ git stash apply Auto-merging bar CONFLICT (content): Merge conflict in bar Recorded preimage for 'bar' $ cat bar <<<<<<< Updated upstream bar ======= baz
>>>>>>> Stashed changes
Phil