在Git存储库中,如何正确重命名目录?

本文翻译自: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 addgit commitpush所有内容。 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: casesensitiveCaseSensitive - 你必须使用两个步骤:

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值