git pull

git checkout master

git checkout -b rebaseexample

git log --graph --pretty-oneline 

 


git checkout myfeaturebranch

git rebase master

** rewind to the beginning of the branch **

** then replay the changes onto the head **


Change the history

 

git rebase HEAD^^^^ -i

 

git rebase --continue

 


Good references:

http://git-scm.com/book/en/Git-Tools-Rewriting-History

 

Note: there is value in your commit history

 

You may want to revise your commit history - rebasing.

- You can decide what files go into the commit from the staging area.

- You can squash several commits into one.

If you you decide you should not be working on something then the stash command is useful.

 


HOWTO: Change the last commit

  • Change the last message
  • Change the files in the last commit

How to: Change your last commit message

git commit --amend


HOWTO: Change the snapshot you just commited

  • Change the files in staging with git add or git rm

git commit --amend

 

The above will take the files in staging and make it the snapshot for the new commit.


HOWTO: Change the last three commit messages 

git rebase -i HEAD~3

ReWrite every commit from HEAD~3 ...HEAD

 


HOWTO: Show the last three commit messages

git log --pretty=format:"%h %s" HEAD~3..HEAD


HOWTO: Pick certain commits and lose others

pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file

to this:

pick 310154e updated README formatting and added blame
pick f7f3f6d changed my name a bit

HOWTO: Squash commits

# Commands:

# p, pick = use commit

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

#

# If you remove a line here THAT COMMIT WILL BE LOST.

# However, if you remove everything, the rebase will be aborted.

 

Try this...

pick f7f3f6d changed my name a bit

squash 310154e updated README formatting and added blame

squash a5f4a0d added cat-file

---

Undo that commit and leaves the modified files unstaged

git reset HEAD^

  • stage the files
  • commit the files
  • repeat....

git rebase --continue

git log -4 --pretty=format:"%h %s"