本文翻译自:In a Git repository, how to properly rename a directory?
I think it should work to copy the directory to be renamed to a new directory with desired name, and delete the old directory , and git add
, git commit
and push
everything. 我认为应该将要重命名的目录复制到具有所需名称的新目录,并删除旧目录 ,然后git add
, git commit
并push
所有内容。 But is this the best way? 但这是最好的方法吗?
#1楼
参考:https://stackoom.com/question/kvPg/在Git存储库中-如何正确重命名目录
#2楼
You can rename the directory using the file system. 您可以使用文件系统重命名目录。 Then you can do git rm <old directory>
and git add <new directory>
( Help page ). 然后你可以做git rm <old directory>
和git add <new directory>
( 帮助页面 )。 Then you can commit and push. 然后你可以提交并推送。
Git will detect that the contents are the same and that it's just a rename operation, and it'll appear as a rename entry in the history. Git将检测到内容是相同的,并且它只是一个重命名操作,它将在历史记录中显示为重命名条目。 You can check that this is the case before the commit using git status
您可以在使用git status
进行提交之前检查是否属于这种情况
#3楼
Basic rename (or move): 基本重命名(或移动):
git mv <old name> <new name>
Case sensitive rename—eg. 区分大小写的重命名 - 例如。 from casesensitive
to CaseSensitive
—you must use a two step: 从casesensitive
到CaseSensitive
- 你必须使用两个步骤:
git mv casesensitive tmp
git mv tmp CaseSensitive
( More about case sensitivity in Git… ) ( 更多关于Git中的区分大小写... )
…followed by commit and push would be the simplest way to rename a directory in a git repo. ...然后提交和推送将是重命名git仓库中的目录的最简单方法。
#4楼
Simply rename the folder. 只需重命名该文件夹即可。 git is a "content-tracker", so the SHA1 hashes are the same and git knows, that you rename it. git是一个“内容跟踪器”,所以SHA1哈希是相同的,git知道,你重命名它。 The only thing that changes is the tree-object. 唯一改变的是树对象。
rm <directory>
git add .
git commit
#5楼
git rm -rf --cached path/to/your/directories
然后重新添加并提交。
#6楼
If you receive this error: fatal: renaming 'foldername' failed: Invalid argument 如果收到此错误:致命:重命名'foldername'失败:参数无效
Try this: 试试这个:
git mv foldername tempname && git mv tempname folderName