如何在Github Repo下重命名两个同名目录



我分叉了一些GitHub存储库,其中有多个目录:

dir_1
dir_2
Dir_1
dir_4
README.md

请注意,dir_1和dir_1具有相同的名称,但包含不同的文件。当我尝试在本地克隆我的分叉repo时,我最终得到了以下带有自述文件的目录:

dir_1
dir_2
dir_4 
README.md

发生的情况是Dir_1不在了,但唯一的Dir_1保留了下来。因此,为了解决这个问题,我认为在本地克隆分叉项目之前,我需要重命名dir_1和dir_1。例如,dir_1将保持相同的名称,但dir_1将重命名为dir_1_old。这是解决这个问题的正确方法吗?如果是这样的话,我该如何实现这一点?否则,对于这类问题,什么是更好的解决方案?

提前感谢

如果您在不区分大小写的文件系统(Windows或MacOS(上工作,目录dir_1Dir_1实际上是;合并的";在磁盘上:您应该在本地dir_1目录中看到dir_1的文件与Dir_1的文件混合在一起。

这里有一种方法可以重命名不区分大小写的文件系统中的一个文件夹:

# start from a clean worktree :
$ git stash
# the following will :
#  * on your disk: move the combined content of Dir_1 and dir_1 to Renamed_1
#  * in git's index: stage the renaming of Dir_1 only
$ git mv Dir_1 Renamed_1
# this will restore the content of dir_1 on your disk :
$ git checkout .
# this will remove the content of dir_1 from Renamed_1 on your disk :
$ git clean -fd Renamed_1
# check your git status : you should see all files from Dir_1/... renamed to Renamed_1/...
$ git status

另一种方法是从区分大小写的文件系统(例如:linux工作站或VM(重命名文件夹


说明如何在这种情况下着陆,以及一些检查git:中存储的内容的示例命令

从以下情况开始:

$ git log --graph --oneline --all
* ba1a040 (HEAD -> right) created Dir_1 and file_right.txt on branch right
| * 3cb290d (left) created dir_1 and file_left.txt on branch left
|/
* 0d2a900 (master) first commit (README.txt)

合并两个分支leftright将导致:

$ git merge left
Merge made by the 'recursive' strategy.
dir_1/file_left.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 dir1/file_left.txt
# in git's storage : there are two distinct directories dir_1 and Dir_1
$ git ls-tree HEAD
040000 tree d6317389dbdebb9fcec7a5f60ba49666bb55cdfb    Dir_1
100644 blob 72943a16fb2c8f38f9dde202b7a70ccc19c52f34    README.txt
040000 tree 9cd36c945344bf39eb3b3fcb642f791f80847dbf    dir_1
$ git ls-tree HEAD:Dir_1
100644 blob 5716ca5987cbf97d6bb54920bea6adde242d87e6    file_right.txt
$ git ls-tree HEAD:dir_1
100644 blob 257cc5642cb1a054f08cc83f2d943e56fd3ebe99    file_left.txt
# when checked out on disk, both directories get "merged"
# (which name wins depends on the order in which the directories were created on disk)
$ ls
README.txt  Dir_1/
$ ls Dir_1/
file_left.txt  file_right.txt

最新更新