Git忽略不起作用 [英] Git Ignore not working

查看:57
本文介绍了Git忽略不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况.我在分支机构A上,对本地工作副本上的某些文件进行了一些更改.

Here is my scenario. I was on branch A, where I made some changes to certain file on my local working copy.

/launcher/file.esb

/launcher/file.esb

我基本上想要以下内容:

I basically want the following:

  1. 完全忽略对该文件所做的更改.我用完成了 假设不变
  2. 从版本控制中取消跟踪此文件,这是我尝试使用.gitignore完成的.

  1. Ignore the changes made to this file completely. I accomplished this using assume-unchanged
  2. Untrack this file from version control, which I tried to accomplish using .gitignore.

在签出其他分支时,将对此文件的更改保留在本地工作文件夹中. A->开发-> B-> C等...

Preserve the changes to this file on my local working folder as I checkout different branches. A->Develop->B->C etc...

这是我无法完成的#3.一旦我签出新分支并进行拉取,旧的更改就会在文件上被覆盖.

It is #3 that I am not able to accomplish. As soon as I checkout a new branch and do a pull, the old changes are overwritten on the file.

为什么会这样?不应将此文件路径包含到.gitignore中,从而完全将其移出版本控制触角所无法及的范围吗?

Why is this happening? Shouldnt inclusion of this file path into .gitignore effectively take out this file completely out of reach of the version control tentacles?

我如何实现#3?

此问题与可能重复"链接中提到的问题不同. 原因如下:

This question is unlike the one mentioned in the "possible duplicate" link. Heres why:

基本上,这就是我平时想要的. 将我的一个特定文件放入一个'shell'中,在任何git操作中都不会覆盖它,也不会在更改时将其考虑在内".它基本上排除了该文件与暂存/远程之间的任何形式的版本控制同步.此本地文件和暂存/远程版本必须存在相互完全断开的连接.

Here's basically what I want in lay words. "Put this one particular file of mine in essentially a 'shell', that neither gets overwritten during ANY git operations nor gets taken into account if changed". Its basically excluding any form of version control synchronization between that file and staging/remote. This local file and the version on staging/remote must exist with mutual and total disconnection.

推荐答案

之所以发生这种情况,是因为该文件已经是存储库的一部分.因此,当您切换分支时,将从要签出的分支中获取此文件的版本. gitignore文件仅阻止git查看不属于存储库的文件.这样就完成了,所以git在诸如git add .git commit -a之类的命令中不包含某些文件.假定未更改的选项将使git看不到更改,但这意味着Git可以在签出时随意覆盖文件,因为它知道文件与提交的版本没有什么不同.

This is happening because the file is already part of the repository. So when you switch branches you get the version of this file from the branch you are checking out. The gitignore file only prevents git from seeing files that are not a part of the repository. This is done, so git doesn't include certain files in commands like git add . or git commit -a. And assume-unchanged option tricks git into not seeing the changes, but that means that Git feels free to overwrite the file on checkouts, since it knows the file to be no different from the committed version.

如果要从git控件中删除此文件并自己管理对其进行的更改,则可以使用git rm --cached /launcher/file.esb并提交更改.这将从索引中删除该文件,并且git将不再跟踪该文件. --cached选项可防止git从工作目录中实际删除文件.不过,您可能必须为每个分支分别进行此操作,因为从一个分支中删除文件并不会从其他分支中将其删除.为此,您可能要撤消假定不变,然后使用git stash命令临时存储本地更改.

If what you want is to remove this file from git control and manage the changes to it yourself, you can use git rm --cached /launcher/file.esb and commit the change. This will remove this file from the index and the file will no longer be tracked by git. The --cached option prevents git from actually removing the file from your working directory. You might have to do this separately for each branch though, since removing file from one branch doesn't remove it from other branches. To do this you might want to undo assume-unchanged and then use git stash command to temporarily stash your local changes.

这篇关于Git忽略不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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