How can I move the root of my git repository?
To start, I’m aware this question has been asked before here.
The thing is that I do like to keep the history.
So I tried out all of the other steps I could find which involve either moving the .git directory one level up or creating a subdirectory and moving all the files from the current root into that. But I keep on losing the history of my files.
The funny thing is that Git Bash (so on my local commmand line) tells me it detects the files as being renamed and when I run
git log I also get the history of the file as I’d expect it. But when I look on github, the history is gone and the commit only contains a list of files being removed and added (instead of a list of renames, which I’d expect).
The repository I’m talking about is this one. There’s a branch called “Moving” in which I tried to move the files around.
In case it helps, the exact steps I took were:
- Create the subdirectory “src” in the directory which contains .git
- Move all the files into that subdirectory
- Move the directories from the level above where .git is, one level down
- Run a
git add srcand
git add nbprojectwhere src is the subdirectory I created in step 1 and nbproject a directory I moved down in step 3
- Run a
git rmfor all “old files”
- Run a
git statusand note that all files are detected as being renamed
- Run a
git log src/READMEto make sure the history is OK
- Finally commit the change to github
- Note that the history is gone when I look at my README on github
One Solution collect form web for “How can I move the root of my git repository?”
Git does not store file copies and renames, it uses heuristics to figure that out. I speculate Github isn’t picking up the rename because they’ve turned off rename/copy heuristics to save processing power. It doesn’t affect much but how that one commit is displayed on Github. Simplest thing to do is just ignore it and keep on coding. Maybe contact Github tech support.
Otherwise, your other option is to rewrite history to make your subdirectory the main directory. This will retain history but change all your commit IDs which may throw off references in log messages and issue trackers. (I do recall a tool that would change commit IDs in log messages, but I can’t remember it.)