Skip to content

Instantly share code, notes, and snippets.

@jhannah
Created August 30, 2013 19:55
Show Gist options
  • Save jhannah/6393686 to your computer and use it in GitHub Desktop.
Save jhannah/6393686 to your computer and use it in GitHub Desktop.
git rebase after changing files which the base branch has MOVED
https://twitter.com/deafferret/status/373530616655917057
Mind. Blown.
Did you know when rebasing in git it even correctly patches files that were MOVED in the base branch? I...
Wow.
<3 git
Here, let me show you:
➜ Jay-Hannahs-iMac:test git init
Initialized empty Git repository in /Users/jhannah/tmp/test/.git/
➜ Jay-Hannahs-iMac:test git:(master) echo 'xxxxxxxxxxxxxxxxxx' > foo
➜ Jay-Hannahs-iMac:test git:(master) ✗ git add foo
➜ Jay-Hannahs-iMac:test git:(master) ✗ git commit -a -m 'added foo'
[master (root-commit) b9e7fb1] added foo
1 file changed, 1 insertion(+)
create mode 100644 foo
➜ Jay-Hannahs-iMac:test git:(master) git checkout -b mybranch
Switched to a new branch 'mybranch'
➜ Jay-Hannahs-iMac:test git:(mybranch) echo 'yyy' >> foo
➜ Jay-Hannahs-iMac:test git:(mybranch) ✗ git commit -a -m 'modified foo'
[mybranch 504ab80] modified foo
1 file changed, 1 insertion(+)
➜ Jay-Hannahs-iMac:test git:(mybranch) git checkout master
Switched to branch 'master'
➜ Jay-Hannahs-iMac:test git:(master) git mv foo bar
➜ Jay-Hannahs-iMac:test git:(master) ✗ git commit -a -m 'moved foo to bar'
[master ff5d0e0] moved foo to bar
1 file changed, 0 insertions(+), 0 deletions(-)
rename foo => bar (100%)
➜ Jay-Hannahs-iMac:test git:(master) git checkout mybranch
Switched to branch 'mybranch'
➜ Jay-Hannahs-iMac:test git:(mybranch) ls
foo
➜ Jay-Hannahs-iMac:test git:(mybranch) cat foo
xxxxxxxxxxxxxxxxxx
yyy
➜ Jay-Hannahs-iMac:test git:(mybranch) git rebase master
First, rewinding head to replay your work on top of it...
Applying: modified foo
Using index info to reconstruct a base tree...
A foo
Falling back to patching base and 3-way merge...
Auto-merging bar
➜ Jay-Hannahs-iMac:test git:(mybranch) ls
bar
➜ Jay-Hannahs-iMac:test git:(mybranch) cat bar
xxxxxxxxxxxxxxxxxx
yyy
ZOMG this is impressive when it Just Works in real life (complicated) code.
I thought for sure I was going to be in trouble when I attempted the real rebase
in this scenario. Nope. git Just Worked. Freaking magic! :D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment