Reputation: 2225
I used to use gitx to stage changes for commit, but I have switched to a purely terminal workflow + Fugitive.vim. One feature that I really miss from gitx though is the ability to make an adjustment in a previous commit. For example, if some section was added in a previous commit, but shouldn't have been, gitx makes it really easy to pull out that section and just amend the previous commit.
My current workflow for making such a change is:
git show
git reset --soft HEAD^
git add -i
to make whatever change I want to makegit commit
What previously was a convenient two step process has now become pretty cumbersome. Is there some other way to do this that I'm missing?
git commit --amend -CHEAD --interactive
seemed promising to me, but it doesn't seem to work at all.
Upvotes: 1
Views: 838
Reputation: 97996
The git command line doesn't know anything about editing files, so you're always going to have two steps: make the change, and apply that change to some commit.
If the commit you want to amend is the most recent on the branch, you can use two of the options to git commit
:
--amend: Replace the tip of the current branch by creating a new commit ... the message from the original commit is used as the starting point, instead of an empty message
--no-edit: Use the selected commit message without launching an editor. For example, git commit --amend --no-edit amends a commit without changing its commit message.
If you want to amend a commit deeper in history, you need to use git rebase --interactive
and change the command against the commit from "pick" to "edit". You then do the same thing, but once you're finished, you run git rebase --continue
so that git replays the changes after that point.
Upvotes: 0
Reputation: 11050
To accomplish the same task I use the following approach:
# Find the starting commit where I need to place changes
git log --oneline --graph --decorate
# Ask for editing commit(s)
git rebase -i {{commit-hash-from-log-history}}
# Enter "edit" for commit(s) you want change, then save
# Add, Edit or Remove files
# Finalize editing
git rebase --continue
# Or, if you want to abort
git rebase --abort
Please, tell me if it works for you too.
Upvotes: 1