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

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

问题描述

我有一个 git 存储库,其结构如下所示:

I have a git repository whose structure looks like:

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

我想将 webapp 文件夹的内容上移一级.我生成的存储库应该如下所示:

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

我可以通过简单地将 webapp 目录中的所有文件向上移动一级,删除空的 webapp 目录然后提交更改来实现吗?这会保留 webapp 目录下文件的提交历史吗?

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?

虽然对你们中的许多人来说是一个非常简单的问题,但我想确定一下.我最不想要的就是 git 汤.

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.

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

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.

据我所知,完成此操作的最佳方法是使用 git-filter.我对 shell 或 git 不太擅长,所以有人可以告诉我我需要执行什么来执行上述操作.

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.

推荐答案

正确的做法是:

git mv repo.git/webapp/* repo.git/.
git rm repo.git/webapp
git add * 
git commit -m "Folders moved out of webapp directory :-)"

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

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