9

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.

lbj-ub
  • 1,425
  • 2
  • 19
  • 34

1 Answers1

4

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

Community
  • 1
  • 1
Justin Howard
  • 5,504
  • 1
  • 21
  • 48