2

I have the following problem: I have a git repo and I want to move the file x.y from directory A to directory B while preserving its history. Then I want to create a new file with the same name (x.y) but a different content in directory A.

I have tryed this using git mv A/x.y B/x.y and then creating a new file x.y in A. But it didn't work the way I wanted to. My git log shows that the file B/x.y was created new (and has no history) and that the old content of file A/x.y was removed and the new content was added (this file still has all the history, where it should have none)

So my question to the git gurus is: Is this possible and how do I do it? Is there maybe a parameter for git add that I can use or something while creating the file?

Foaly
  • 565
  • 1
  • 7
  • 22
  • Unfortunately git moved files detection & handling isn't that good, which is why you notice things like this. – dtech Sep 23 '15 at 11:57

1 Answers1

0

Try a git log --follow -- b/x.y: you should see the log history of x.y even before the move.

--follow

Continue listing the history of a file beyond renames (works only for a single file).

If you wanted to not use --follow, you would need git filter-branch.

However, that won't be visible on GitHub (nor BitBucket).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok I see. But it doesn't show up that way on Github... edit: using `git log --follow` – Foaly Sep 23 '15 at 11:44
  • @Foaly `git log` is you doing something on your local machine, it doesn't affect github. Github would need to use the command/implement a similar system in their view for it to be able. – dtech Sep 23 '15 at 11:56
  • @dtech I think the OP means that, once pushed to GitHub, the extended history (with --follow) would no longer be visible. – VonC Sep 23 '15 at 11:57