首页 > 解决方案 > 如何从远程拉,而在本地忽略文件?

问题描述

在 git 中,我根据对question的回答使用 .git/info/exclude 忽略了本地文件。但现在我不能从远程拉,这是我得到的错误:

git pull 

error: Your local changes to the following files would be overwritten by 
merge: ignoredFile

Please commit your changes or stash them before you merge.

所以我尝试提交这个文件:

git commit -am "Message"


On branch master
Your branch is behind 'origin/master' by 4 commits, and can be fast- 
forwarded.
    (use "git pull" to update your local branch)

nothing to commit, working tree clean

所以问题就像标题一样,如何保持存储库更新(git pull),同时忽略本地的特定文件。

编辑:我跑了赞扬:

git update-index --assume-unchanged ignoredFile 

在 git 拉之前。

编辑2:

git pull --rebase


error: Your local changes to the following files would be overwritten by merge:
    ignoredFile
Please commit your changes or stash them before you merge.
Aborting
Updating 0f37f00b..5ccc1b0a
First, rewinding head to replay your work on top of it...
error: Your local changes to the following files would be overwritten by checkout:
    ignoredFile
Please commit your changes or stash them before you switch branches.
Aborting could not detach HEAD

标签: git

解决方案


可能您正在寻找:

$ git pull --rebase 

这将更新您的分支并在不创建新分支的情况下向前移动您的更改,但不会忽略您的本地文件,以便您可以在需要时推送它们或从中创建分支。


推荐阅读