I recently committed a file to the HEAD of my branch which has errors in it. I need to do the following things:
What's the best way of going about that?
You want both local and remote to appear as though this never happened. First git reset --hard HEAD^ You've now blown away all local changes from the last commit. Then: git push --force origin HEAD This takes the current HEAD commit in local and overwrites the HEAD in the remote, removing the last commit.
Find the commit you want, change pick to e ( edit ), and save and close the file. Git will rewind to that commit, allowing you to either: use git commit --amend to make changes, or.
You've practically said it yourself:
First get the file back from one commit before:
$> git checkout HEAD~1 path/to/file.ext
Then commit it:
$> git commit -a -m 'Retrieved file from older revision'
If only the changes to that file where present in the last commit, you can even use git-revert
:
$> git revert HEAD
I think it would be better to make this a separate commit, because it tells you exactly what you've reverted, and why. However, you can squash this into the previous commit by using the --amend
switch to git-commit
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With