GIT忽略已使用排除对本地更改提交的文件 [英] GIT Ignore already commited files using exclude for local changes

查看:1434
本文介绍了GIT忽略已使用排除对本地更改提交的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了有三个文件的远程仓库。

  file1.txt 
file2.txt
file3.txt

所做的更改是在我的机器上本地进行的,文件名为file3.txt。我不希望更改进入远程回购,反之亦然。



我使用.gitignore读取它,不可能忽略已经提交和跟踪的文件。



我决定使用以下行的.git / info / exclude文件

排除文件

  file3.txt 

但是仍然在file3.txt中所做的更改显示为unstaged文件。我希望这个file3.txt在commit和staging中被忽略,并且还需要阻止file3.txt从远程repo进行更新。

预先感谢任何帮助

解决方案


我使用.gitignore读取它,不可能忽略已经提交和跟踪的文件。 p>

.gitignore .git / b















$ b

  git rm --cached file3.txt 

只要从缓存中删除(而不是从硬盘驱动器),一个 git status 不应该显示它(因为它已经在 .gitignore



请参阅 git rm --cached x vs git reset head - x :cache ,也称为索引或暂存区域,删除来自索引的文件并将其保存在工作副本中。

file3.txt 将不再在版本库中进行版本升级。如果你只需要

https://stackoverflow.com/a/14462290/6309\">在本地签署文件一段时间后,您可以尝试:

  git update-index --assume-unchanged  -  file3.txt 

注意:根本不涉及 .gitignore



停止本地忽略更改:

  git update-index --no-assume-unchanged  -  file3.txt 


I cloned the remote repository which is having three files

file1.txt 
file2.txt
file3.txt

changes are made locally in my machine into file3.txt. I don't want the changes to go into remote repo and vice versa.

I read that using .gitignore it is not possible to ignore the already commited and tracked file.

I decided to use .git/info/exclude file with the following line

exclude file

file3.txt

But still changes made in file3.txt are shown as unstaged file. I want this file3.txt to be ignored in commit and staging and also need to prevent file3.txt to update from remote repo

Thanks in advance for any help

解决方案

I read that using .gitignore it is not possible to ignore the already commited and tracked file.

It is, with the .gitignore or .git/info/exclude.

You just need to record the deletion of that file first.

git rm --cached file3.txt

As soon as it is deleted (from the cache only, not from the hard drive), a git status should not show it (since it is already in the .gitignore)

See ""git rm --cached x" vs "git reset head — x"?": "cache", also called "index" or "staging area", removes the file from index alone and keeps it in your working copy.

file3.txt will no longer be versionned in the repo.
And that will propagate to other clones once that deletion will have been committed and push.


If you only need to ignore the file locally for a while, you can try instead:

git update-index --assume-unchanged -- file3.txt

Note: that doesn't involve .gitignore at all.

To stop locally ignoring changes:

git update-index --no-assume-unchanged -- file3.txt

这篇关于GIT忽略已使用排除对本地更改提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆