If the commit you want to fix isn’t the most recent one:
git rebase --interactive $parent_of_flawed_commit
If you want to fix several flawed commits, pass the parent of the oldest one of them.- An editor will come up, with a list of all commits since the one you gave.
- Change
pick
toreword
(or on old versions of Git, toedit
) in front of any commits you want to fix. - Once you save, git will replay the listed commits.
- Change
- Git will drop back you into your editor for every commit you said you want to reword, and into the shell for every commit you wanted to edit. If you’re in the shell:
- Change the commit in any way you like.
git commit --amend
git rebase --continue
Most of this sequence will be explained to you by the output of the various commands as you go. It’s very easy, you don’t need to memorise it – just remember that
git rebase --interactive
lets you correct commits no matter how long ago they were.
Source: link.
UPDATE:
Another way to go:
Source: link.
UPDATE:
Another way to go:
git commit --amend
Used to amend the tip of the current branch. Prepare the tree object you would want to replace the latest commit as usual (this includes the usual -i/-o and explicit paths), and the commit log editor is seeded with the commit message from the tip of the current branch. The commit you create replaces the current tip -- if it was a merge, it will have the parents of the current tip as parents -- so the current top commit is discarded.
It is a rough equivalent for:
but can be used to amend a merge commit.$ git reset --soft HEAD^ $ ... do something else to come up with the right tree ... $ git commit -c ORIG_HEAD
Source: link.
No hay comentarios:
Publicar un comentario