使用 Git 覆盖本地文件丢弃所有本地文件和目录以及 git 来自 repo 的完整最新代码

Override local files with Git Pull | Discard all local files and directories and git the complete latest code from the repo

我想从 git 服务器获取完整的最新代码,并且需要覆盖我的本地计算机更改。这意味着我想删除我所有的本地未跟踪文件和目录,而不是从远程存储库获取最新代码。 git 可以吗?

试试这个:

git reset --hard HEAD
git pull

虽然你会失去任何不在回购协议中的东西

根据你的问题,我明白了,你必须删除所有你未跟踪的文件(你在本地机器上更改的文件)并从远程存储库获取最新代码并保留你的 git 树干净的。如果我的理解是正确的,请在下面找到这个问题的解决方案:

Please note when you do this, you will loose all your uncommitted local changes.

步骤 1 删除未跟踪文件

git checkout .
git clean -f

步骤 2 删除未跟踪目录

git clean -f -d

步骤 3 获取最新代码

git fetch --all
git reset --hard <remote>/<branch_name>

例如

git checkout .
git clean -f
git clean -f -d
git fetch --all
git reset --hard origin/master