Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Moving Files into Folders

Tags:

git

github

I am quite new to git and version control in general, and have question about moving files around. I have a master repo on GitHub, with 6 source files.

I've done a lot of work on the project and now my local branch contains two folders with the sources in those.

The directory structure used to be like:

Master:

  • File 1
  • File 2
  • File 3
  • File 4
  • File 5
  • File 6

Where as my local branch now looks like this:

New Folder 1:

  • New File 1
  • New File 2
  • New File 3

New Folder 2:

  • File 1
  • File 2
  • File 3
  • File 4
  • File 5
  • File 6

How can I move my local structure to the master branch without losing my commit history on the old files?

like image 650
james_dean Avatar asked Feb 11 '12 01:02

james_dean


2 Answers

Just commit. Git blame etc will generally do a pretty good job of automatically detecting moves.

like image 97
Amber Avatar answered Oct 14 '22 09:10

Amber


git doesn't actually track "moves" of files, it infers it on demand from similar content. So, just make the move and add / remove files as appropriate. (You will make life easier for the tools in future if you avoid making changes to the content as well as moving them in a single commit.)

Then, to see the log accounting for moves, use -M, -C, or their variants to git log. Similar flags apply to other tools, and you should read the help to understand the detail of what they do.

If you use git mv on a file, it just does the git rm and git add for you.

like image 30
Daniel Pittman Avatar answered Oct 14 '22 09:10

Daniel Pittman