Reputation: 38714
This is a common problem I run into with git. Someone sends me a set of files. I make some changes, then commit. Then I remember that I forgot to commit the state of the files before I made the changes. I still have a copy of the original files. How can I retroactively check in the unchanged version, then have the next commit be my changed version?
(I have tried overwriting my changed version with the old version, committing, then reordering the commits with rebase -i
, but I always get a conflict when I try that, because my original commit adds all the files, and rebase doesn't seem to like reordering an add to be after a modify)
Upvotes: 0
Views: 44
Reputation: 39973
With the usual caution about git reset --hard
, which throws away uncommitted changes as well as the changes between the original and destination commits:
git branch tmp
git reset --hard HEAD^
cp ../originals/* .
git add . # or whichever specific files
git commit -m "Add original files"
git checkout tmp -- .
git commit -c tmp
git branch -D tmp
You could use the reflog instead of a temporary branch if you're comfortable with that, of course.
Upvotes: 1