4

Possible Duplicate:
Is it possible to move/rename files in git and maintain their history?

I am a previous subversion user, not sure how git could help me in following situation.

I have a git repository where my project was contained having multiple dirs, I've been making several commits over this structure

Now I need to make structure changes, so that I move all folders/files at root to a new folder, and I still want to keep commit history of files.

so for example in my repo I currently have a structure like this

src
res
xml
file.txt
.gitignore

I want all of them to be moved in a folder called common, so that I have following structure at the root of repo

common
.gitignore

Is it possible , if so how ?

Thank you

Community
  • 1
  • 1
Ahmed
  • 14,503
  • 22
  • 92
  • 150
  • Don't think its duplicate of the reference you gave, the questioner there already seems to know what I want to know. hence the answers there are based on that assumption. – Ahmed Nov 24 '12 at 23:59

2 Answers2

4
mkdir common
git mv src res xml file.txt common
git commit
melpomene
  • 84,125
  • 8
  • 85
  • 148
  • This won't maintain the history for these files. You would need to `git log --follow` to see the history. – Ryan Bigg Nov 24 '12 at 23:34
  • 4
    Yes, it will. Or rather it can't because git does not track per-file history. It always tracks the history of the whole repository. – melpomene Nov 24 '12 at 23:36
4

You could use commands like this

mkdir common
git mv src res xml file.txt common

This moves the files and you can still see the history with git log --follow common/file.txt. If you'd rather rewrite history, check out How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?

Community
  • 1
  • 1
fidian
  • 813
  • 7
  • 10