How to return a file to Git that has been renamed

I would like to return the file that was renamed, say, now it is called B, to the fact that it was in an earlier commit, for example, it is called A, how would I do this, while preserving the history? File B was pressed.

I can view the entire history of file B, including when it was named A, using:

git log --follow pathToFileB

This shows me a list of commits that this file participated in, but I'm not sure what to do next.

Normally I would do a git checkout commitId:pathToFile , but in this case it does not work.

+6
source share
1 answer

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 fooobar.com/questions/4093 / ...

+2
source

Source: https://habr.com/ru/post/978216/


All Articles