繁体   English   中英

Git-添加一个移动的文件夹来提交

[英]Git - adding a moved folder to commit

我是Git的新手,遇到了一些问题:

我创建了一个包含其他文件和文件夹的文件夹,将主文件夹添加到git中并提交。 ". 之后,我将其中一个子目录移到另一个子目录(仍在主目录中)中,然后再次键入“ git add -A ”。 然后我输入“ git commit -m'initial commit'”。 I moved is not part of the commit. 但是,我看到我移动的不属于提交。

也许我没有正确移动子目录? 我究竟做错了什么?

之前

Star Wars
    Empire Forces
        Chewie
    Rebel Forces
mv Star Wars/Empire Forces/Chewie Star Wars/Rebel Forces

Star Wars
    Empire Forces
    Rebel Forces
        Chewie
git add -A "Star Wars" 
git commit -m "initial commit"

要将子目录移动到其他目录,应使用:

git mv [-v] [-f] [-n] [-k] <source> ... <destination directory>

该目录必须由git索引。 mv命令不这样做...

如果您不使用它,git将不知道目录在哪里。

成功完成后,索引将更新,但更改仍必须提交。

[git文档]

您可以执行以下操作从存储库中删除旧目录,然后添加新目录。

这将以递归方式从存储库中删除旧目录及其所有子目录。
git rm -r --cached <old-directory-location>

然后像往常一样做git add
git add <new-directory-location>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM