Skip to content

Instantly share code, notes, and snippets.

@catharinejm
Last active April 4, 2016 15:34
Show Gist options
  • Save catharinejm/553b9c0195f74ce795008398c981400f to your computer and use it in GitHub Desktop.
Save catharinejm/553b9c0195f74ce795008398c981400f to your computer and use it in GitHub Desktop.
Trouble with squash merges
# Create a fresh repo
$ git init testsquash
Initialized empty Git repository in /Users/jon/Code/Sterf/testsquash/.git/
$ cd testsquash
# Commit a file to master
$ echo foo >> file
$ git add .
$ git ci -m foo
[master (root-commit) 20d8a88] foo
1 file changed, 1 insertion(+)
create mode 100644 file
# Create a branch 'a' off of master
$ git co -b a
Switched to a new branch 'a'
# Modify the existing file and commit
$ echo bar >> file
$ git ci -m"bar" .
[a 94ec413] bar
1 file changed, 1 insertion(+)
# Create a branch 'b' off of 'a'
$ git co -b b
Switched to a new branch 'b'
# Rename the file...
$ git mv file newfile
$ git st
On branch b
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: file -> newfile
# ...and alter the contents enough that git can't tell it's a rename
$ echo new contents > newfile
$ git add .
$ git st
On branch b
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: file
new file: newfile
# ...and commit
$ git ci -m newfile
[b ef9d4dc] newfile
2 files changed, 1 insertion(+), 2 deletions(-)
delete mode 100644 file
create mode 100644 newfile
# Squash merge branch 'a' into master
$ git co master
Switched to branch 'master'
$ git merge --squash a
Updating 20d8a88..94ec413
Fast-forward
Squash commit -- not updating HEAD
file | 1 +
1 file changed, 1 insertion(+)
$ git ci -m"a"
[master 0e052b3] a
1 file changed, 1 insertion(+)
# And try to squash merge branch 'b' into master
$ git merge --squash b
CONFLICT (modify/delete): file deleted in b and modified in HEAD. Version HEAD of file left in tree.
Squash commit -- not updating HEAD
Automatic merge failed; fix conflicts and then commit the result.
$ git st
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: newfile
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by them: file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment