2

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:

  1. Create the subdirectory "src" in the directory which contains .git
  2. Move all the files into that subdirectory
  3. Move the directories from the level above where .git is, one level down
  4. Run a git add src and git add nbproject where src is the subdirectory I created in step 1 and nbproject a directory I moved down in step 3
  5. Run a git rm for all "old files"
  6. Run a git status and note that all files are detected as being renamed
  7. Run a git log src/README to make sure the history is OK
  8. Finally commit the change to github
  9. Note that the history is gone when I look at my README on github
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Vincent
  • 1,459
  • 15
  • 37
  • have you heard about submodules? subtree? – CodeWizard Feb 15 '15 at 19:00
  • same question has an answer at http://stackoverflow.com/a/3247756/1587370 – pratZ Feb 15 '15 at 19:02
  • @pratZ, I tried that, same effect. It works on the command line, locally, but github refuses to keep the file history. – Vincent Feb 15 '15 at 19:08
  • @jsexpert, how are submodules a solution to my problem? Please elaborate. – Vincent Feb 15 '15 at 19:08
  • Submodule allow you to "have" an inner repository inside another repository, in your case the src dir can be a stand alone repository with the full history. Since you moved the files manually without git rm (git rm save the history) you lost the history. gut subtree/submodule allow you to manage an inner repo. – CodeWizard Feb 15 '15 at 19:12
  • 1
    @jsexpert, according to this: http://stackoverflow.com/questions/7434449/why-use-git-rm-to-remove-a-file-instead-of-rm a `git rm` only saves some typing by running a `rm` followed by a `git add`. So I don't see how I lost my history because I didn't use `git rm`. And are you saying I need to start a second repository? – Vincent Feb 15 '15 at 19:25

1 Answers1

2

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.)

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • BFG Repo Cleamer does fix commit ids in the message, but I do not think that it does file moves. – Joseph K. Strauss Feb 16 '15 at 01:39
  • @JosephK.Strauss: No, BFG Repo-Cleaner does not do file moves, it's only for sanitizing stuff. However, regular `git filter-branch` should be able to do it (though more slowly). – sleske Feb 16 '15 at 18:59
  • @sleske Much slower, and there is no way to automatically convert commit hashes in messages. – Joseph K. Strauss Feb 16 '15 at 19:41