how to ignore files that are already tracked in git

家住魔仙堡 提交于 2019-12-11 16:01:56

问题


I tried to pull origin a.

and go the following:

error: Your local changes to the following files would be overwritten by merge:
    src/.cproject
    src/.project
    src/navigate/navigate_main.c
Please, commit your changes or stash them before you can merge.
Aborting

git status showed:

    modified:   .gitignore
modified:   src/.cproject
modified:   src/.project
modified:   src/navigate/navigate_main.c

I did git rm --cached src/.project to the first 3, and stashed the 4th

I did pull again and unstashed my changes.

however when I do pull origin a

I get:

M   .gitignore
U   src/.cproject
M   src/navigate/navigate_main.c
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

how can I clean this once and for all?


回答1:


Your git rm --cached src/.project doesn't do much good unless you commit the change. Why not just git stash everything, then pull, stash pop, and then remove the ignored files with rm --cached?




回答2:


Uncommitted changes are always bad. You have to decide whether those changes are good or bad. If they are good, commit them. If the are bad, discard them.

Once you have no more uncommitted changes you have no more problems.

Have a look at git status or git status --short to see any uncommitted changes.

Configure a meaningful prompt to see what is going on immediately. For bash add something like this to your ~/.bashrc:

PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
GIT_PS1_SHOWDIRTYSTATE=yes
GIT_PS1_SHOWSTASHSTATE=yes
GIT_PS1_SHOWUNTRACKEDFILES=yes
GIT_PS1_SHOWUPSTREAM=auto


来源:https://stackoverflow.com/questions/18300301/how-to-ignore-files-that-are-already-tracked-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!