0

I have a lot of files in a single folder 1st Year Project in my Repository

I just want to sort them semester-wise into separate folders like :

  • 2nd Semester Programs
  • 3rd Semester Programs
  • Miscellaneous

I tried to move just one file (Bubble_Sort.cpp) to see if it works

GIT HELP

but, as you can see, it says 6 minutes ago. However, I actually wrote that program 5 months ago. Also, I clicked on the file to see the commit history, and it shows only the commits after it was renamed.

No history

It did recognise that it was a move/rename, but all the commit history was lost.

I went through a lot of online material and did my research, but it was still of no use. I used this command :

git mv "1st Year Project Solution\1st Year Project\Bubble_Sort.cpp" "1st Year Project Solution\2nd Semester Programs\"`

How do I move a file so that the initial creation date is saved or, at least, all the commits made to that file should be there when I click on the history?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
DollarAkshay
  • 2,063
  • 1
  • 21
  • 39

2 Answers2

0

You did it right. You use git mv. Git handles moving a file by deleting the original and creating a new file at the new location with the original contents. So the "moved" file is really a "new" file rather than your old file.

That is why with the moved file you only have the one commit in the history. Before that commit the file didn't exist. That being said, you can still see the history of the file before the move by using git log --follow as mentioned in this answer

Community
  • 1
  • 1
Schleis
  • 41,516
  • 7
  • 68
  • 87
  • Thank you :) Running the command : `git log --follow -p "1st Year Project Solution\2nd Semester Programs\Bubble_Sort.cpp"` actually showed me the entire history :) – DollarAkshay Sep 11 '14 at 16:16
  • I would be helpful if I could view this information on the git website itself :) – DollarAkshay Sep 11 '14 at 16:17
0

Presuming you don't care about preserving any of the existing SHAs then this would be a case to run 'git filter-branch' and rewrite the history with the files are their new locations.

Andrew C
  • 13,845
  • 6
  • 50
  • 57