0

I would like to move a file from one folder to another. File currently resides in /dist/somefile.js, I would rename and move to a different location into a new folder /src/my-newfolder/index.js.

I understand when using the mv command, git is deleting the file and recreating it in its new location. The problem is I lose all my commit history.

I've seen many post on stack saying to use git log --follow ./path/to/file but not how it should be used.

should I be doing

git mv /dist/somefile.js /src/my-newfolder/index.js

git log --follow /src/my-newfolder/index.js

I have spent best part of this afternoon looking at this and, there doesn't seem to be a straight forward answer to achieving to what one would think should be an easy thing to do!

thank you.

david-l
  • 623
  • 1
  • 9
  • 20
  • Yes, `git log --follow /src/my-newfolder/index.js` is exactly what you will want to do in the future when you want to see the history of the file. – someone May 31 '23 at 19:07
  • @Mat yes it's inside the same repo – david-l May 31 '23 at 20:10
  • @someon I use sourcetree which has an option to view log history, do you know if it would give me the I history that way? If not, is there no other way to do this? – david-l May 31 '23 at 20:14
  • Well, one think I find a bit frustrating is that the `--follow` option only works when you're getting the log of a single file. Anything involving more than one file, and it's shown as separate file delete and file add operations. I don't know sourcetree, however. – someone Jun 01 '23 at 14:22

0 Answers0