Reputation: 1423
I'd like to revert a file that has been renamed, say it's now called B, to what it was in an earlier commit, say it was called A, how would I do this while still preserving the history? File B has been pushed.
I can see the entire history of file B, including when it was named A, using:
git log --follow pathToFileB
This shows me a list of commits which this file was involved in, but I'm not sure what to do from there.
Normally, I'd do git checkout commitId:pathToFile
, but this doesn't seem to work in this case.
Upvotes: 9
Views: 3148
Reputation: 5643
You can overwrite file B with the old contents of file A with:
git show commitId:pathToFileA > pathToFileB
You can read more in this answer to a similar question https://stackoverflow.com/a/888623/4231110
Upvotes: 4