Skip to content

Instantly share code, notes, and snippets.

@AshleyGrant
Created February 18, 2015 17:54
Show Gist options
  • Save AshleyGrant/bdf8f4cc36bb45999879 to your computer and use it in GitHub Desktop.
Save AshleyGrant/bdf8f4cc36bb45999879 to your computer and use it in GitHub Desktop.
How to rebase a branch
Ashley@WE2015DEV ~/git_temp
$ git init
Initialized empty Git repository in c:/Users/Ashley/git_temp/.git/
Ashley@WE2015DEV ~/git_temp (master)
$ echo 1 > file.txt
Ashley@WE2015DEV ~/git_temp (master)
$ git add file.txt
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
Ashley@WE2015DEV ~/git_temp (master)
$ git commit -m "Add text '1'"
[master (root-commit) 5fe21b4] Add text '1'
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+)
create mode 100644 file.txt
Ashley@WE2015DEV ~/git_temp (master)
$ git checkout -b branch
Switched to a new branch 'branch'
Ashley@WE2015DEV ~/git_temp (branch)
$ echo 2 > file.txt
Ashley@WE2015DEV ~/git_temp (branch)
$ git add .
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
Ashley@WE2015DEV ~/git_temp (branch)
$ git commit -m "Add text '2'"
[branch warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
3d1e15d] Add text '2'
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+), 1 deletion(-)
Ashley@WE2015DEV ~/git_temp (branch)
$ git checkout master
Switched to branch 'master'
Ashley@WE2015DEV ~/git_temp (master)
$ echo 3 > file.txt
Ashley@WE2015DEV ~/git_temp (master)
$ git add file.txt
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
Ashley@WE2015DEV ~/git_temp (master)
$ git commit -m "Add text '3'"
[master warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
8be6aa0] Add text '3'
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+), 1 deletion(-)
Ashley@WE2015DEV ~/git_temp (master)
$ git checkout branch
Switched to branch 'branch'
Ashley@WE2015DEV ~/git_temp (branch)
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Add text '2'
Using index info to reconstruct a base tree...
M file.txt
Falling back to patching base and 3-way merge...
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Failed to merge in the changes.
Patch failed at 0001 Add text '2'
The copy of the patch that failed is found in:
c:/Users/Ashley/git_temp/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Ashley@WE2015DEV ~/git_temp (branch|REBASE 1/1)
$ echo 2 > file.txt
Ashley@WE2015DEV ~/git_temp (branch|REBASE 1/1)
$ git add file.txt
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
Ashley@WE2015DEV ~/git_temp (branch|REBASE 1/1)
$ git rebase --continue
Applying: Add text '2'
Ashley@WE2015DEV ~/git_temp (branch)
$ git log
commit 2995352608f0374631459eb5c71493dc8cc15637
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:41:09 2015 -0500
Add text '2'
commit 8be6aa0205bf4ef18f4906a3aa6df39f0a95e024
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:41:37 2015 -0500
Add text '3'
commit 5fe21b4baaa2a5ad2c8b864488b80726a49074e6
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:40:03 2015 -0500
Add text '1'
Ashley@WE2015DEV ~/git_temp (branch)
$ echo 4 > file.txt
Ashley@WE2015DEV ~/git_temp (branch)
$ git add file.txt
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
Ashley@WE2015DEV ~/git_temp (branch)
$ git commit -m "Add text '4'"
[branch warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
2562e12] Add text '4'
warning: LF will be replaced by CRLF in file.txt.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+), 1 deletion(-)
Ashley@WE2015DEV ~/git_temp (branch)
$ git checkout master
Switched to branch 'master'
Ashley@WE2015DEV ~/git_temp (master)
$ git merge branch
Updating 8be6aa0..2562e12
Fast-forward
file.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Ashley@WE2015DEV ~/git_temp (master)
$ git log
commit 2562e12fa609e03be7aecac80d5e0fa4656ecf9d
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:51:55 2015 -0500
Add text '4'
commit 2995352608f0374631459eb5c71493dc8cc15637
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:41:09 2015 -0500
Add text '2'
commit 8be6aa0205bf4ef18f4906a3aa6df39f0a95e024
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:41:37 2015 -0500
Add text '3'
commit 5fe21b4baaa2a5ad2c8b864488b80726a49074e6
Author: Ashley Grant <[email protected]>
Date: Wed Feb 18 12:40:03 2015 -0500
Add text '1'
Ashley@WE2015DEV ~/git_temp (master)
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment