我如何移动我的git仓库的根目录? [英] How can I move the root of my git repository?

查看:339
本文介绍了我如何移动我的git仓库的根目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我知道这个问题已经在此处
问题是我喜欢保存历史记录。



因此,我尝试了其他所有可以找到的步骤,包括移动.git目录上一级或创建一个子目录,并将当前根目录下的所有文件移动到该目录中。但是我一直在丢失我的文件的历史。



有趣的是,Git Bash(所以在我的本地命令行中)告诉我它检测到文件被重命名当我运行 git log 时,我也可以获得文件的历史记录。但是当我看着github时,历史消失了,提交只包含了被删除和添加的文件列表(而不是我希望的重命名列表)。

我正在讨论的存储库是这一个。有一个名为Moving的分支,我试图移动文件。



如果有帮助,我采取的确切步骤是:


  1. 在包含.git的目录中创建子目录src
  2. 将所有文件移动到该子目录中
  3. >
  4. 将目录从上面的.git所在的级别移动到下一级

  5. 运行 git add src git add nbproject 其中src是我在步骤1中创建的子目录,nbproject是我在步骤3中移动的目录

  6. 为所有旧文件运行一个 git rm 运行一个 git status 并注意所有文件被检测为重命名

  7. 运行 git log src / README 以确保历史记录正常

  8. 最后将更改提交给github

  9. 请注意,当我在github上查看自述文件时,历史消失


解决方案

Git do不存储文件副本和重命名,它使用启发式来解决这个问题。我猜测Github没有选择重命名,因为他们已经关闭了重命名/复制启发式以节省处理能力。它并没有太大影响,但是如何在Github上显示那个提交。最简单的事情就是忽略它并继续编码。也许联系Github技术支持。

否则,您的其他选择是重写历史记录以使你的子目录成为主目录。这将保留历史记录,但会更改所有提交ID,这些ID可能会在日志消息中引发引用并发出跟踪器。 (我确实记得一个工具可以在日志消息中更改提交ID,但我记不清它了。)


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

解决方案

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

这篇关于我如何移动我的git仓库的根目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆