I had previously complete and committed a complex update affecting multiple files. Call this commit #1.
Then I did some house cleaning deleting a couple unused files and making a duplicate of one old report for comparison purposes. Committed those changes. Call this commit #2.
Then I found another change that needed to be made which really belonged in commit #1.
A quick google search brought me here: See Answer #3. http://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit
I had already saved my file changes but not committed - hoping for a way to go back in time. I opened the file and kept it open in my editor. Then in command line, repeating those instructions, I did the following:
- git reset --hard
This erases my changes (which I'll add back in a second)
- git rebase 0ek7sffd1z^ --interactive
This shows me the commits between HEAD and the commit I want to add to
I edited the beginning of the line from 'pick' to 'edit' for the commit I want.
Then 'CTRL+x', then 'Y'
Now I'm in branch ((no branch))
Then in my editor I save the file I had open with my changes.
- git status
This shows my edited file unstaged
- git add myeditfile.ext
- git status
This shows my edited file staged
- git commit --amend
- git rebase --continue
Now I'm back on my active branch having completed time travel.
I laugh out loud as disbelief fades because that really just happened!
Git rises to immortal hero status in my mind.
Git saves the world one more time. The world barely noticed, but Git is my hero once again!
Post a Comment