3

I have this situation in my dev directory with git:

/mobile.html
/sub-folder/mobile.html

This is the same file with commits in both places. I worked on mobile.html in root first and then moved it to /sub-folder but its commits never followed. I continued to work on it and made new commits.

So now I basically have:

  • /mobile.html - commit a, commit b
  • /sub-folder/mobile.html - commit c, commit d

Is there anyway to join the commit history on these two files?

Mat
  • 202,337
  • 40
  • 393
  • 406
Anatoly
  • 159
  • 2
  • 5

2 Answers2

3

I think what you're seeing here is you being unaware of the fact Git does not track histories of individual files (!). In Git model, only content is tracked, and its distribution across all the files present in a given repository snapshot (what a commit represents) is irrelevant. Hence renames are not tracked in any specific way, and the git mv command is just a convenience helper for git rm --cached <filename> && mv <filename> <othername> && git add <othername>.

To compensate for the perceived discontinuity of the change history of a file, Git has special knobs in its history traversal commands which might be used to tell Git how hard it should try to detect what a human would perceive as a file rename. In particular, look at the --follow, --find-renames and --find-copies command-line options of the git log command.

kostix
  • 51,517
  • 14
  • 93
  • 176
0

If you moved the files and commited without modifying them, git is able to know that this is a move and not a delete + new files.

Gaetan
  • 488
  • 4
  • 13