Download Pragmatic Guide to Git

Transcript
E RASING C OMMITS
117
Erase with an interactive rebase.
prompt> git rebase -i <commit to erase>^
For example, to erase commit c2d2245, use this:
prompt> git rebase -i c2d2245^
... launches editor ...
Delete the line that contains the c2d2245 commit, and then save and exit the
editor so git rebase can run.
Erase with git rebase --onto.
For example, imagine these commits in your repository:
c2d2245
/
2245d2c
/
/
o--o--o--o
\
\
\
HEAD
224cd25
Use the following to delete commits 224cd25 and 2245d2c:
prompt> git rebase --onto c2d2245 HEAD^ HEAD
First, rewinding head to replay your work on top of it...
Applying: add API object for interacting with remote API
And after the rebase is successful, the branch looks like this:
c2d2245
/
o--o
\
HEAD
Erase the last commit.
prompt> git reset --hard HEAD^
Related Tasks
• Task 16, Rewriting History by Rebasing, on page 60
• Task 36, Reverting Commits, on page 112
• Task 40, Retrieving “Lost” Commits, on page 120
Report erratum
Download from Wow! eBook <www.wowebook.com>
this copy is (P1.0 printing, October 2010)