如何将文件夹层次结构中的所有git内容向上移动一级? [英] How can I move all git content one-level up in the folder hierarchy?

查看:474
本文介绍了如何将文件夹层次结构中的所有git内容向上移动一级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git仓库,其结构如下:

  +  -  repo.git 
|
+ ---- + bootstrap.py
+ ---- + buildout.cfg
+ ---- +。gitignore
+ ---- + webapp
|
+ --------- + manage.py
+ --------- +模块
+ --------- +模板
+ --------- + static
+ --------- + ...
+ --------- +。 ..

我想移动 webapp 文件夹上一级。我生成的回​​购应该是这样的:

  +  -  repo.git 
|
+ ---- + bootstrap.py
+ ---- + buildout.cfg
+ ---- + .gitignore
+ ---- +管理。 py
+ ---- +模块
+ ---- +模板
+ ---- +静态
+ ---- + ...
+ ---- + ...

我可以通过将所有文件上一层的 webapp 目录,删除空的 webapp 目录,然后提交更改?这会保留 webapp 目录下文件的提交历史记录吗?



尽管对于许多你,我想确定。我想要的最后一件事是一个git汤。




我试着移动文件,但是我失去了提交历史记录git并没有真正处理移动或重命名。我知道即使它在日志中显示为新文件,仍然可以使用 git log 中的某些选项查看文件的提交历史记录。



从我读过的书中,最好的方法是使用 git-filter 。我对shell或git不太好,所以有人可以告诉我需要执行上述操作。

解决方案

刚刚做到了,实际上它非常简单。正确的做法是 -

  git mv repo.git / webapp / * repo.git /。 

然后

  git rm repo.git / webapp 

后跟一个

  git add * 
git commit -m文件夹移出webapp目录:-)


I have a git repository whose structure looks like:

+--repo.git
|
+----+bootstrap.py
+----+buildout.cfg
+----+.gitignore
+----+webapp
|
+---------+manage.py
+---------+modules
+---------+templates
+---------+static
+---------+...
+---------+...

I would like to move the contents of the webapp folder one level up. My resulting repo should look like:

+--repo.git
|
+----+bootstrap.py
+----+buildout.cfg
+----+.gitignore
+----+manage.py
+----+modules
+----+templates
+----+static
+----+...
+----+...

Can I do this by simply moving all the files of the webapp directory one level up, deleting the empty webapp directory and then committing the changes? Would this preserve the commit history of the files under the webapp directory?

Although a very simple question for many of you, I'd like to be sure. The last thing I'd want is a git soup.


I tried moving the files but I lost the commit history as git doesn't really handle a move or a rename. I do know that even though it shows up as a new file in the logs, it is still possible to view the commit history for the file using some options in git log.

From what I've read, the best way to accomplish this would be using git-filter. I'm not very good with shell or git so could someone tell me what I'd need to execute to do the aforementioned.

解决方案

Just did this, and it is pretty simple actually. The right way to do this is -

git mv repo.git/webapp/* repo.git/.

and then

git rm repo.git/webapp

followed by a

git add * 
git commit -m "Folders moved out of webapp directory :-)"

这篇关于如何将文件夹层次结构中的所有git内容向上移动一级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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