如何忽略 Git pull 中出现的以下错误消息?
以下文件的本地更改将被合并覆盖
如果我想要重写它们怎么办?
我尝试了像 git pull -f
这样的方法,但都没有起作用。
需要明确的是,我只想覆盖特定的更改,而不是所有的更改。
git stash --patch
选择性地隐藏您要放弃的更改,然后使用git stash drop
丢弃这个隐藏。然后您可以正常地拉取远程更改并合并它们。git reset --hard && git pull
由于你的分支比 'origin/dev' 落后 xx 次提交,可以进行快进合并。尝试运行此命令:
git checkout .
git pullenter code here
git clean -f
命令清除未跟踪的文件。 - John错误 "您在本地所做的更改会被合并覆盖" 是因为您在本地仓库中进行了一些尚未提交的更改,因此在从远程仓库拉取之前,请先提交本地仓库中的更改。
假设您的远程仓库有一个名为xyz的分支,您希望将该远程仓库xyz分支合并(复制)到本地仓库xyz分支中,则:
{
git checkout xyz //check out to the respective branch in local repo
git commit -m "commiting message" //commit changes if any, in local repo branch xyz
git pull //it pulls remote xyz branch into local xyz branch
}
示例
[root@localhost www]# git pull
Username for 'http://159.65.151.11': amol
Password for 'http://amol@159.65.151.11':
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 34 (delta 13), reused 0 (delta 0)
Unpacking objects: 100% (34/34), done.
From http://159.65.151.11/OpenCC
f793c8e..b8fe60c v1.18.0_24Feb2022 -> origin/_v1.18.0_24Feb2022
error: Your local changes to the following files would be overwritten by merge:
cc/routes/web.php
Please, commit your changes or stash them before you can merge.
Aborting
git checkout HEAD^ cc/routes/web.php
git pull
git pull upstream master
时,出现了以下错误:
为了解决这个问题,我进行了以下操作错误:合并会覆盖以下文件的本地更改: myfile.js 请在合并之前提交您的更改或将其存储。 中止
git update-index --no-assume-unchanged myfile.js
git status
命令,然后收到了这个消息。
然后我执行了On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: myfile.js ** ^^^^ THIS IS KEY ^^^^^ - FILE SHOULD APPEAR MODIFIED!! no changes added to commit (use "git add" and/or "git commit -a")
git checkout myfile.js
,接着是git pull upstream master
。这次git pull操作成功了。git diff foobar.js
命令,确认没有丢失重要内容后再执行 git restore foobar.js
命令。 - jakebugz617git update-index --skip-worktree dockerfile
的变更,现在我可以通过 git update-index --no-skip-worktree dockerfile
来恢复它。 - Devin Rhode我有一个特殊的情况:我有一个文件上面打了 --assume-unchanged 标记。这个文件很难找到,因为 git status
命令没有显示任何更改。
git add
git checkout mybranch
将会有效。我不太确定为什么有效。
在拉取代码之前,您必须提交所有尚未提交的文件,这样您就不会收到AS的那条消息。
我在从主分支pull代码时遇到了这个问题。
我使用Visual Studio处理的方法如下:
希望这能有所帮助!
git config core.fileMode false
的意思是“关闭 Git 对文件模式的检查”,这将节省我的时间。 - Nolwennig