简体   繁体   English

我可以使用git提交文件,但在执行git svn dcommit时会自动忽略它吗?

[英]Can I commit a file with git, but automatically ignore it when doing a git svn dcommit?

I'm starting now to adopt Git for my personal workflow at an SVN office, so git-svn is a tool I'm going to be relying on heavily. 我现在开始在SVN办公室采用Git作为我的个人工作流程,所以git-svn是我将依赖的工具。 One issue I've come across that I don't know how to resolve is how to ignore in one direction. 我遇到的一个我不知道如何解决的问题是如何忽视一个方向。

The specific use case for me is that our ant build file references things like svn and svnversion. 我的具体用例是我们的ant构建文件引用了svn和svnversion之类的东西。 Obviously, if I'm using git-svn, I'm not planning on using either of those. 显然,如果我使用git-svn,我不打算使用其中任何一个。 I have replaced them in my local build.xml with git equivalents, which are working just fine. 我已经在我的本地build.xml中使用git等效替换它们,这些工作正常。

However, I clearly don't want to commit that change in a git svn dcommit. 但是,我显然不想在git svn dcommit中提交更改。 I want to keep this change locally, and commit it locally so I don't lose it, but I don't want it to ever get committed back to the main SVN repo, because it will break pretty much the entire company's use of SVN, if I do. 我想在本地保留这个更改,并在本地提交它,所以我不会丢失它,但我不希望它再次被提交回主SVN仓库,因为它会破坏整个公司对SVN的使用, 如果我做。 A similar case using SVN alone is presented in this question . 这个问题中提出了仅使用SVN的类似案例。

Is there any solution that would allow me to commit build.xml locally, continue to take build.xml changes from SVN (which has a lot of stuff not related to SVN as well), and never commit it back up using dcommit, without jumping through hoops every time I try to commit? 有没有任何解决方案可以让我在本地提交build.xml,继续从SVN(它有很多与SVN无关的东西)进行build.xml更改,并且永远不会使用dcommit提交备份,而不会跳转每次我尝试提交时通过篮球?

Yes, you can. 是的你可以。

As you noted, you can't gitignore files that are already tracked. 如您所述,您无法gitignore已经跟踪的文件。 But what you can do is tell your index that it should pretend that no changes exist for certain files: 但你可以做的是告诉你的索引它应该假装某些文件不存在任何变化:

git update-index --assume-unchanged <file>

If you want to stop ignoring changes for that file (for example, because you made a change to build.xml that you do need to share with other team members), then use: 如果要停止忽略该文件的更改(例如,因为您对build.xml进行了更改,而您需要与其他团队成员共享),请使用:

git update-index --no-assume-unchanged <file>

Warning: if you directly add the file with git add <file> , it will assume that you really mean that you want to add that file, and the --assume-unchanged directive will be ignored. 警告:如果直接使用git add <file> ,它将假定您确实想要添加该文件,并且将忽略--assume-unchanged指令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM