我有一个叫做foo的项目。在我的机器上,这个项目位于一个名为foo_container的非git文件夹的子文件夹中(即,在foo_container/foo中)。foo是一个git文件夹,我还将其同步到github,并做了一些更改。
稍后,我在foo_container下的其他文件夹中添加了更多内容(如foo_container\foo_docs),并希望从现在起将foo_container签入作为回购。我不想丢失foo的git历史,但是当然,从现在开始,foo_container的更改是可以记录的。
做这件事最干净的方法是什么?下面是我考虑过的几个选项:
备选案文1:
cd /path/to/foo_container
git init
<rename repository on github from foo to foo_container>
<some git-remote command - I don't know what this should be to switch existing repo>选项2(可能有效,但我怀疑我会丢失foo目录的git历史记录)
删除github上的旧foo回购,创建一个名为foo_container、git init in foo_container和git-remote add origin <...foo_container.git>的新回购
我不知道这两种办法是否有效,哪一种更好。
发布于 2014-12-02 06:49:12
第一种方法很好,因为您可以将foo声明为foo_container的子模块。
但最简单的办法是:
foo重命名为foo_container (所以foo_container/foo_container)git mv foo_container/foo_container在新文件夹“foo”(foo_container/foo_container/foo)下的内容foo_container\foo_docs中复制foo_container/foo_container/foo_docs:添加、提交和推送foo_containerfoo_container/foo_container。发布于 2014-12-02 06:50:54
foo中的所有内容移到一个名为foo的子目录中(以便您将foo/foo作为您的实际项目)。采取这一行动。foo_container移到foo中,这样您就可以拥有foo/foo_docs之类的东西了。添加并提交所有这些。foo成为顶级foo_container目录,并删除旧目录。即在foo_container期间,做mv foo ../foo_container2,cd ..,rmdir foo_container,mv foo_container2 foo_container。发布于 2014-12-02 06:48:06
不如..。
cd foo_container/foo
mkdir foo
git mv * foo/
git commit -m "Move foo to subfolder"你的结构是..。
foo_container/
foo/
.git/ (git repo data)
foo/ (actual contents you've been tracking)
bar/ (other thing you want to add)然后,将当前在foo_container/foo中的所有内容直接移动到foo_container中(包括.git目录),使您的结构为.
foo_container/
.git/ (git repo data)
foo/ (actual contents you were tracking)
bar/ (other thing you want to add)现在,foo_container中所有不是foo的东西都将显示为要添加到git存储库中的新文件,而git存储库现在是基于foo_container的,而foo仍然会显示为一个文件夹,因为有了git mv,在旧的提交中仍然会有历史记录。
git add bar
git commit -m "Add bar"
git push origin HEADhttps://stackoverflow.com/questions/27243379
复制相似问题