Git如何忽略指定文件 - Git how to ignore specified file

- 此内容更新于:2016-02-02
主题:

假设我的git仓库有2个分支:branch1文件。exe配置。xmlbranch2文件。exe配置。xml存储库都包含相同的文件。但在运行它覆盖这个文件的每个分支都包含自己的版本。如果我想从我得到错误,文件配置。xml被改变了。我试图忽略这个文件,但是之后删除配置。远程服务器上的xml。我试过了。这之后我可以推动远程服务器虽然配置。xml是改变了但我仍然不能切换到另一个分支。错误:我的问题-有办法忽略文件在本地存储库,所以我可以把远程服务器或切换到另一个早午餐而不是删除此文件吗?和不错的选项将把这个文件当我需要手动。

原文:

Suppose I have a git repository with 2 branches:

  • branch1

    • file.exe
    • config.xml
  • branch2

    • file.exe
    • config.xml

Both of repositories contain the same files. But after running file.exe it overwrites config.xml so each branch contains its own version of this file.

If I want to git checkout branch2 from branch1 I get error that file config.xml was changed. I tried to ignore this file with .gitignore but after git push remoteserver it removes config.xml on remote server.

I tried git update-index --assume-unchanged config.xml. After this I can push to remote server although config.xml was changed but I still can't switch to another branch. The error: Entry 'config.xml' not uptodate. Cannot merge. So my question - is there way to ignore file in local repository so I can push to remote server or switch to another brunch but not to remove this file at all? And nice option will be to push this file when I need manually.

网友:将此文件添加到.gitignore

(原文:add this file to .gitignore)

网友:@Babul他已经试过,除外的问题。

(原文:@Babul He already tried that, q.v. the question.)

网友:你想成为版本吗?你会考虑让文件完全无足迹的Git?

(原文:Do you want config.xml to be versioned at all? Would you consider making the file completely untracked by Git?)

网友:这意味着你的。gitignore不工作对吗?

(原文:that means your .gitignore is not working right ?)

网友:我试图忽略这个文件。gitignore但gitpushremoteserver后删除配置。远程服务器上的xml。——这是应该发生什么,当你删除一个文件从版本控制。当然,它会显示在远程服务器上运行时,不是吗?

(原文:I tried to ignore this file with .gitignore but after git push remoteserver it removes config.xml on remote server. - that is what is supposed to happen when you remove a file from version control. Surely, it will appear on the remote server when it runs the file.exe, no?)

解决方案:
忽略congif。在任何路径创建xml。gitignore**/config.xml,并添加一个条目。同步运行或然后提交
原文:

To ignore congif.xml in any path Create .gitignore and add a entry **/config.xml. To resync run

git rm -r --cached . 

or

git rm –cached `git ls-files -i –exclude-standard`

then commit

楼主:它会删除在远程服务器吗?

(原文:Will it remove config.xml on remote server after git push?)

网友:服务器上的文件可能仍然存在,但下次别人拉分支的文件不会被更新。你需要重新考虑设计。

(原文:The file may still be there on the server, but next time someone else pulls from the branch the file will not be updated. You need to rethink your design here.)

网友:@folibis移除它从远程服务器,你必须删除它在地方和推动提交到远程。

(原文:@folibis to remove it from remote server you have to delete it in local and push the commit to remote.)

楼主:不,那正是我想要的,该文件将保持在服务器上。我以后再试一试。谢谢

(原文:No, that exactly what I want, that the file will stay on the server. I'll try it later. Thanks)