1

I'm planning to wholesale refactor my entire project.

It may mean some file renaming, but mostly it will involve a lot of re-organizing of files.

New directories being created, files moving from one directory to another, or from one to a new directory etc.

Will git and my repo maintain it's history under these changes?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
chris P
  • 6,359
  • 11
  • 40
  • 84
  • possible duplicate of [Is it possible to move/rename files in git and maintain their history?](http://stackoverflow.com/questions/2314652/is-it-possible-to-move-rename-files-in-git-and-maintain-their-history) – Lasse Jul 07 '15 at 01:39

1 Answers1

0

If you want to refactor in GIT and move files but still keep track of their history you need to use git mv.

Due to the way that git manages the content (It save in different places the content and the metadata of the file names) you must do it using git mv

Once you do git mv and move files to their new location git will mark the files as renamed which means that its still keeping its history but the file was renamed - not the content simply the file name/path

thekbb
  • 7,668
  • 1
  • 36
  • 61
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • so if I have a file /project/alpha/myfile, I would first move it to project/beta/myfile, then use git mv, and finally git add/commit/push? – chris P Jul 07 '15 at 02:28
  • Almost - move it with git mv and it will move your files to the new location. – CodeWizard Jul 07 '15 at 05:07
  • I disagree! If you (mostly) didn't change the content of the files, you could move the files without 'git mv' and it will find out the rename/moving when you add the files to the stage area (based on the similarity). – Philippe Jul 07 '15 at 06:19
  • You can do it by simply moving the files but the preferred way is to use `git mv` to be sure that it behave as expected. – CodeWizard Jul 07 '15 at 07:04
  • @codeWizard Weird. I moved every single file via `git mv`. However, after check in, nothing has retained history. For example if I did a `git mv /dirA/fileZ dirB/`, and then I open up bitbucket and browse my repo, and look at fileZ, it no longer has any history except for the most recent commit. – chris P Jul 08 '15 at 05:32