I recently committed a file to the HEAD of my branch which has errors in it. I need to do the following things:
- Get that file from one commit previous to HEAD
- Commit that file back into HEAD
What’s the best way of going about that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ve practically said it yourself:
First get the file back from one commit before:
Then commit it:
If only the changes to that file were present in the last commit, you can even use
git revert: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
--amendswitch togit commit.