Reputation: 8471
say I have the following commit history :
4317629 Bug-100 : Formatting / Cosmetic Changes
da10348 Bug-100 : Wire Up UI
9b49b0a Bug-100 : Added UI
Now, say I find that in the commit da10348
, I had a few files : a.txt
, b.txt
, c.txt
that contain lines that I need to remove / fix.
Can someone tell me just how I can do that?
Upvotes: 1
Views: 178
Reputation: 73645
This is the method I find the easiest for doing small fixes to recent commits, because it requires just one rebase command (i.e. no git rebase --continue
) and doesn't involve remembering commit hashes.
git rebase -i origin/master
if the commit has not yet been pushed to origin, or alternatively git rebase -i HEAD~3
based on how far in the history the commit to change is (it's OK to overestimate - the older commits won't be changed)f
or fixup
.Upvotes: 1
Reputation: 23633
Note that you can only do this if you're comfortable rewriting history for all descendant commits of the commit you want to change. Otherwise you should just make the change at the tip of your current master branch.
If you do want to do it you can execute
git checkout da10348
# make changes
git commit -a --amend
git rebase --onto <amended-sha> da10348 <your-branch>
Or if you prefer interactive rebase
git rebase -i da10348^
# change "pick da10348" to "edit da10348"
# save, and make changes when rebase -i stops at da10348
Upvotes: 1
Reputation: 681
You have to rebase your branch onto the commit you want to change in order
to change the history after the commit so actually in this case you have to rebase
your branch on the commit before the one you want to change( ^
operator):
git rebase -i da10348^
change the commit to edit and implement your changes and then:
git commit -a --amend --no-edit
and finally finish the rebase:
git rebase --continue
Upvotes: 1