Git git 忽略,忽略不了,搞不定了,谁来帮忙看看~

piginzoo · 2014年04月07日 · 最后由 piginzoo 回复于 2014年04月09日 · 4169 次阅读

要忽略文件,放到.gitignore 里面,这个我是知道的,只可惜我做晚了,我已经把 data/config.php 文件放到 master 里面了,又 push 到 origin/master里面了,然后悲剧就此开始了。

stackoverflow 上的帖子说: http://stackoverflow.com/questions/1139762/gitignore-file-not-ignoring “ If you are trying to ignore changes to a file that's already tracked in the repository (e.g. a dev.properties file that you would need to change for your local environment but you would never want to check in these changes) than what you want to do is:

git update-index --assume-unchanged ”

可是,我这样做了,再 commit 到本地 master 上,也很赞,说文件 data/config.php 没有变, 可我要去 push 到 origin/master 上的时候,我一 pull,悲剧出现了,说我这个 data/config.php 需要 merge!!!

我怎么才能彻底地让所有人(本地,远程)都彻底忽略这个文件呢?

有谁有这种困扰,快来指点一下把~

git rm -r --cached . git add . git commit -m “fixed untracked files” git push

@hanluner 谢谢,这个方法试过了,不行。我的问题我已经把文件提交到库里了“files that's already tracked in the repository”,参考这片,也是这个问题:http://ruby-china.org/topics/17948

先把这个文件删掉提交一次,让他处于被删的状态,这时在试着去 ignore 看行不行

看看 filter branch 能不能从整个 commit 历史中把它删除,然后写好 .gitignore 把它提交上。

新建一个 delign 分支,把文件删掉,然后 rebase。

git rm xxx.xxx --cached

git rm & commit,然后再修改 igonre 就可以了

git filter-branch --index-filter "git rm -r --cached filename.extension --ignore-unmatch"  HEAD
git push origin master -f
# add to ignore file
git rm -r --cached data/config.php

然后 commit,应该可以的

-r
  Allow recursive removal when a leading directory name is given.
--cached
  Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

@Justin 嗯,-r 就是直接删除掉,我其实最后就是这么解决了,直接 git rm data/config.php,然后再重新人肉添加,世界清静了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号