SVN:有没有办法将文件标记为“不提交"? [英] SVN: Is there a way to mark a file as "do not commit"?

查看:23
本文介绍了SVN:有没有办法将文件标记为“不提交"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 TortoiseSVN,我可以将文件移动到提交时忽略更改列表中,这样当我提交整个树时,对该文件的更改不会被提交.

With TortoiseSVN, I can move a file into the ignore-on-commit changelist, so that when I commit a whole tree, changes to that file do not get committed.

有没有办法使用 svn 命令行工具做类似的事情?

Is there a way to do something like that using the svn command-line tool?

感谢使用 svn:ignore 的建议,但这并不能满足我的要求.

Thanks for the suggestions to use svn:ignore, but that doesn't do quite what I was looking for.

svn:ignore 影响诸如 svn add &svn 导入.它给了它一个要忽略的文件名模式列表.

svn:ignore affects things like svn add & svn import. It gives it a list of filename patterns to ignore.

我有一个已经在源代码控制之下的文件,但我想对该文件进行临时更改,我不想在提交整个源代码树时提交该文件.我正在进行许多其他更改,我可以在我的监视器上贴一个注释,告诉我在提交树之前还原该文件,但如果 svn 可以自动跳过该文件,那就太好了.

I have a file that's already under source control, but I want to make temporary changes to that file that I don't want to be committed later on when I commit the whole source tree. I am making a lot of other changes and I could stick a note on my monitor telling me to revert that file before I commit the tree, but it would be nice if svn could automatically skip that file.

推荐答案

Subversion 没有内置的不提交"/提交时忽略"功能,截至 2016 年 2 月/版本 1.9.这个答案是一个非理想的命令行解决方法

正如 OP 所述,TortoiseSVN 有一个内置的更改列表,忽略提交",它会自动从提交中排除.命令行客户端没有这个,所以你需要使用多个更改列表来完成同样的行为(有警告):

  • 你想要提交的工作[工作]
  • 你想忽略的事情[ignore-on-commit]

因为 TortoiseSVN 有先例,所以我在示例中使用忽略提交"来处理我不想提交的文件.我将对我所做的文件使用工作",但您可以选择任何您想要的名称.

Since there's precedent with TortoiseSVN, I use "ignore-on-commit" in my examples for the files I don't want to commit. I'll use "work" for the files I do, but you could pick any name you wanted.

首先,将所有文件添加到名为work"的更改列表中.这必须从您的工作副本的根目录运行:

First, add all files to a changelist named "work". This must be run from the root of your working copy:

svn cl work . -R

这会将工作副本中的所有文件递归添加到名为work"的更改列表中.这样做有一个缺点 - 当新文件添加到工作副本时,您需要专门添加新文件,否则它们将不会被包含在内.其次,如果您必须再次运行它,则需要再次重新添加所有提交时忽略"文件.不理想 - 您可以像其他人一样开始在文件中维护自己的忽略"列表.

This will add all files in the working copy recursively to the changelist named "work". There is a disadvantage to this - as new files are added to the working copy, you'll need to specifically add the new files or they won't be included. Second, if you have to run this again you'll then need to re-add all of your "ignore-on-commit" files again. Not ideal - you could start maintaining your own 'ignore' list in a file as others have done.

然后,对于要排除的文件:

Then, for the files you want to exclude:

svn cl ignore-on-commit path	ofile-to-ignore

因为文件只能在一个更改列表中,所以在您之前的工作"添加之后运行此添加将从工作"更改列表中删除您想要忽略的文件,并将其放入提交时忽略"更改列表中.

Because files can only be in one changelist, running this addition after your previous "work" add will remove the file you want to ignore from the "work" changelist and put it in the "ignore-on-commit" changelist.

当您准备好提交您希望提交的修改后的文件时,您只需将--cl work"添加到您的提交中:

When you're ready to commit your modified files you do wish to commit, you'd then simply add "--cl work" to your commit:

svn commit --cl work -m "message"

这是我机器上的一个简单示例:

Here's what a simple example looks like on my machine:

D:workspace	runk>svn cl work . -R
Skipped '.'
Skipped 'src'
Skipped 'srcconf'
A [work] srcconfdb.properties
Skipped 'srcjava'
Skipped 'srcjavacom'
Skipped 'srcjavacomcorp'
Skipped 'srcjavacomcorpsample'
A [work] srcjavacomcorpsampleMain.java
Skipped 'srcjavacomcorpsamplecontroller'
A [work] srcjavacomcorpsamplecontrollerController.java
Skipped 'srcjavacomcorpsamplemodel'
A [work] srcjavacomcorpsamplemodelModel.java
Skipped 'srcjavacomcorpsampleview'
A [work] srcjavacomcorpsampleviewView.java
Skipped 'src
esource'
A [work] src
esourceicon.ico
Skipped 'src	est'

D:workspace	runk>svn cl ignore-on-commit srcconfdb.properties
D [work] srcconfdb.properties
A [ignore-on-commit] srcconfdb.properties

D:workspace	runk>svn status

--- Changelist 'work':
        srcjavacomcorpsampleMain.java
        srcjavacomcorpsamplecontrollerController.java
        srcjavacomcorpsamplemodelModel.java
M       srcjavacomcorpsampleviewView.java
        src
esourceicon.ico

--- Changelist 'ignore-on-commit':
M       srcconfdb.properties

D:workspace	runk>svn commit --cl work -m "fixed refresh issue"
Sending        srcjavacomcorpsampleviewView.java
Transmitting file data .done
Committing transaction...
Committed revision 9.

另一种方法是简单地将您希望提交的每个文件添加到工作"更改列表中,甚至不维护忽略列表,但这也需要大量工作.真的,唯一简单、理想的解决方案是是否/何时在 SVN 中实现.在 Subversion 问题跟踪器 SVN-2858 中有一个长期存在的问题,在事件在未来发生变化.

An alternative would be to simply add every file you wish to commit to a 'work' changelist, and not even maintain an ignore list, but this is a lot of work, too. Really, the only simple, ideal solution is if/when this gets implemented in SVN itself. There's a longstanding issue about this in the Subversion issue tracker, SVN-2858, in the event this changes in the future.

这篇关于SVN:有没有办法将文件标记为“不提交"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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