Skip to content

Instantly share code, notes, and snippets.

@HaydenElza
Last active January 19, 2024 21:27
Show Gist options
  • Save HaydenElza/0a36b14c00e8833907f2f8f4a365c7a9 to your computer and use it in GitHub Desktop.
Save HaydenElza/0a36b14c00e8833907f2f8f4a365c7a9 to your computer and use it in GitHub Desktop.
Git amend second to last commit.

Amend Second to Last Commit

Steps

  1. Stash any unstaged changes

  2. Rebase to desired commit

    git rebase -i HEAD~2
    
    # Optionally use `git commit -i <sha1>~` if you don't want to count
  3. Change pick to edit for the desire commmit
    Hint: In vim press i to enter insert mode and press esc + : + wq to save and quit.

  4. Make the changes you want to amend to the commit and stage them with:

    git add .
  5. Amend the commit with:

    git commit --amend

    Hint: In vim press press : + wq to save and quit.

  6. Finish the rebase by running:

    git rebase --continue

Resources

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