我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制在 git pull 上覆盖本地文件 ? 我的本地仓库包含一个与服务器相同的文件名文件 。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
对于那些不喜欢重置的人,我喜欢这样的做法:
git checkout branchname # go to your branch
git fetch origin branchname # fetch the remote
git checkout -b backup # optionally, mark your remote as a backup
git branch -f branchname origin/branchname # force your local branch to be equal to the fetched origin/branchname
其他回答
对于那些不喜欢重置的人,我喜欢这样的做法:
git checkout branchname # go to your branch
git fetch origin branchname # fetch the remote
git checkout -b backup # optionally, mark your remote as a backup
git branch -f branchname origin/branchname # force your local branch to be equal to the fetched origin/branchname
看起来最好的办法是首先做到:
git clean
以删除所有未跟踪的文件,然后继续使用通常的 Git 调用...
这将删除所有未承诺的更改, 然后拉动 :
git reset --hard HEAD
git pull
我不清楚为什么有人还没说到fack_head呢。
git fetch origin master && git reset --hard FETCH_HEAD
如果您想把它放在别名中, 命令是:
git config --global alias.fpull '!git fetch origin master && git reset --hard FETCH_HEAD'
i 总结了其他答案。 您可以执行 Git 调用, 且不出错 :
git fetch --all
git reset --hard origin/master
git reset --hard HEAD
git clean -f -d
git pull
警告: 此脚本非常强大, 这样您就可以丢失更改 。