我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
我如何强制将本地文件覆盖在git pull
我的本地仓库包含一个文件名文件名与服务器上的文件名相同。
错误: 未跟踪的工作树文件“ example. txt ” 会被合并覆盖
当前回答
您可能会发现此命令有助于丢弃本地更改 :
git checkout <your-branch> -f
然后进行清理(从工作树上移走未追踪的文件) :
git clean -f
如果您想要除去未跟踪的文件之外, 还要删除未跟踪的目录 :
git clean -fd
其他回答
步骤1。 (可选择)
从本地主控件库的根根, 保存备份和空当前文件夹:
mkdir -p ../<branch>-bkp && mv --backup=t * ../<branch>-bkp
步骤2从远程仓库下载分支的所有文件和文件夹 :
git checkout <branch> && git add -A . && git reset --hard origin/<branch> && git pull
替换位置<branch>
使用要覆盖的分支的名称。
评论:
git pull
内步骤2,git reset --hard
会git reset --hard origin/<branch_to_overwrite>
不要先从本地主控库删除所有文件和文件夹, 请小心, 任何仍然埋在周围的垃圾文件都可能偷偷潜入远程仓库 。git push
即使这不是你的本意git add -A .
内步骤2如果您选择退出, 防止发生这种情况步骤1.参考文献:
https://gitforwindows.org/
https://www.atlassian.com/git/tutorials/undoing-changes/git-reset
https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog
我认为答案很可怕,但虽然赫奇猪的答案可能更好,但我不认为它能有那么优雅。fetch
和merge
使用定义的战略, 从而保存您本地的更改, 只要它们不是您试图强制覆盖的文件之一 。
git add *
git commit -a -m "local file server commit message"
git fetch origin master
git merge -s recursive -X theirs origin/master
-X
是一个选项名称,并且theirs
是此选项的值。 您选择使用their
更改(另一个选项是ours
如果有冲突,则更改。
所需经费:
解决方案 :
获取获取与 a 具有清洁联 联 年 月 日 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 日 月 月 月 日 月 月 日 月 月 月 日 月 的 月 月 月 日 月 月 日 月 的 月 月 月 月 日 月 月 月文件 文件和目录目录目录目录忽略忽略. jutignore( )和硬重置重置至来源来源.
git stash --include-untracked
git fetch --all
git clean -fdx
git reset --hard origin/master
在 Windows 上执行此单命令 :
git fetch --all & git reset --hard origin/master
对于那些不喜欢的人reset
我喜欢这个方法:
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