如何在执行 git pull
命令时强制覆盖本地文件?我的本地仓库中包含与服务器上相同文件名的文件。
错误:无法完成合并,未跟踪的工作树文件 'example.txt' 将被覆盖。
如何在执行 git pull
命令时强制覆盖本地文件?我的本地仓库中包含与服务器上相同文件名的文件。
错误:无法完成合并,未跟踪的工作树文件 'example.txt' 将被覆盖。
FETCH_HEAD
。git fetch origin <your e.g. feature branch>
git reset --hard FETCH_HEAD
我尝试了 HEAD
和 git pull
,但都没有成功。
public/images/*
拉取更改后,从你的gitignore文件中删除那行。
git stash
暂存任何未提交的更改,然后运行。git pull --rebase=interactive -s recursive -X theirs
drop
,这将使它们消失并让您停留在远程分支的头部,而不会引入合并提交。git stash apply
。我的本地更改很小,或者我的更改没有生效。我只想将所有内容重置为原始状态。我知道所有我的本地更改都将丢失。
如果是这种情况:
git reset --hard
git pull
1:重置到之前的提交
git reset --hard HEAD
2:删除未跟踪的文件
git clean -f
3:拉取提交
git pull
Sources:
对于那些不喜欢使用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
由于二进制文件无法合并,简单的答案是:错误:未跟踪的工作树文件“public/images/icon.gif”将被合并覆盖
git checkout public/images/icon.gif
使用该命令,文件将可以在当前分支下恢复到之前的状态。
如果我不想丢失我的修改,我通常会运行 git stash
命令,如果我不关心本地修改的文件,我会使用类似于 git checkout .
的命令。在我看来,这比使用 reset --hard
,clean
等命令更简单易懂。这些命令更适用于保留分支的状态(包括提交和未跟踪的文件),而不仅仅是解决本地修改的文件。
git restore file_to_override_from_remote
git pull
git clean -f -d
origin/branch_to_overwrite
相同的状态,包括代码和提交记录。命令为:git reset --hard origin/branch_to_overwrite
。 - Andrew Atkinsongit branch <branch> -D
git reset <commit> --hard
git branch <branch>
git --set-upstream-to=origin/<branch> <branch>
git pull
git config core.autocrlf false; git ls-files -z | xargs -0 rm; git checkout .
。 - Chloe