Skip to content

Instantly share code, notes, and snippets.

@todgru
Last active September 26, 2023 00:25
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save todgru/5158779 to your computer and use it in GitHub Desktop.
Save todgru/5158779 to your computer and use it in GitHub Desktop.
git rebase interactive remove commit

#git rebase -i <sha>

List of commits from git log

F--E--D--C--B--A

Lets say you want to remove commit D from the commits.

git rebase -i E

This will open up an editor with all the commits since E.

pick D commit message of D
pick C commit message of C
pick B commit message of B
pick A commit message of A

Delete line D. Write and quit.

New commit log:

F--E--C--B--A

May have to push --force to origin.

reference see Interactive http://git-scm.com/docs/git-rebase reference http://stackoverflow.com/a/37267/1478950

@nlessani
Copy link

nlessani commented May 10, 2023

Just to avoid confusion, the new commit log would actually be:
F--E--C'--B'--A'
The commit hash for the commits above or after the changed commits will be different, even though the code changes are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment