我将一个目录从tools
重命名为Tools
并提交。此后,我的远程仓库中有两个目录。由于某种原因,git没有删除旧的tools
目录。如何避免这种情况或解决当前问题?
Tools
目录视为全新的目录,并将其添加到版本控制中。
To fix the issue, you could ask git to delete the older directory named tools
:
git rm -r tools
git commit
An alternative would be git add -u
, which checks the current state of your working directory and updates the staging area to reflect this state. So git would become aware of any directories that were removed behind its back.
# From the root of your repo
git add -u .
git commit
And for the future, use git mv
to perform the rename, instead of performing the rename directly in the Shell or Command prompt. Although git is smart enough to track the move if it finds a significant similarity between deletions and additions, I prefer informing git explicitly about the move operation.
git mv tools Tools
git commit
git rm
命令,因为我没有这个目录。我使用的是 Windows 操作系统(所以文件系统不区分大小写)。git add -u
命令也没有任何作用。再次尝试使用 git mv
命令也不起作用,因为我没有这个目录。 - user14416我建议你:
git reset --hard HEAD^
(确保您没有任何进行中的工作,或者先将其隐藏)git mv tools Tools
git push --force
git add --all
包括删除和创建。 - TheBuzzSaw