我可以使用git提交文件,但是在执行git svn dcommit时自动将其忽略吗? [英] Can I commit a file with git, but automatically ignore it when doing a git svn dcommit?

查看:61
本文介绍了我可以使用git提交文件,但是在执行git svn dcommit时自动将其忽略吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在开始在SVN办公室的个人工作流程中采用Git,因此git-svn是我将高度依赖的工具.我遇到的一个我不知道如何解决的问题是如何在一个方向上忽略.

对我来说,特定的用例是我们的ant构建文件引用了诸如svn和svnversion之类的东西.显然,如果我使用的是git-svn,则我不打算使用其中任何一个.我已经在我的本地build.xml中用git等效项替换了它们,它们工作正常.

但是,我显然不想在git svn dcommit中提交该更改.我想在本地保留此更改,然后在本地提交,以免丢失,但我不希望将其提交回主要的SVN存储库,因为这将破坏整个公司对SVN的使用, 如果我做. 此仅使用SVN的类似案例问题.

是否有任何解决方案可以让我在本地提交build.xml,继续从SVN(也有很多与SVN不相关的东西)中进行build.xml更改,并且从不使用dcommit提交备份,而每次我尝试提交时都不会跳过障碍?

解决方案

是的,可以.

如前所述,您不能gitignore已被跟踪的文件.但是您可以做的就是告诉您的索引,它应该假装某些文件不存在任何更改:

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

如果您想停止忽略对该文件的更改(例如,由于您确实需要与其他团队成员共享对build.xml所做的更改),请使用:

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

警告::如果您直接使用git add <file>添加文件,则将假定您确实要添加该文件,而--assume-unchanged指令将被忽略.

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. 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. Obviously, if I'm using git-svn, I'm not planning on using either of those. I have replaced them in my local build.xml with git equivalents, which are working just fine.

However, I clearly don't want to commit that change in a 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. A similar case using SVN alone is presented in this question.

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?

解决方案

Yes, you can.

As you noted, you can't gitignore files that are already tracked. 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:

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提交文件,但是在执行git svn dcommit时自动将其忽略吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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