SVN: Is there a way to mark a file as “do not comm

2019-01-02 16:58发布

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.

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

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

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

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.

17条回答
余生请多指教
2楼-- · 2019-01-02 17:24

Some of the proposed ideas can be implemented like this:

On Windows in PowerShell

add all to default list.ps1

dir -Recurse | ? { -not $_.PSIsContainer } | % { svn cl default $_.FullName }

add to ignore list.ps1

 dir file1 ... filN  % { $_.FullName } > ignore-on-commit
 cat .\ignore-on-commit | % { svn cl ignore-on-commit $_ }
 svn add ignore-on-commit

Now, you can alias svn ci --changelist default so that you don't have to specify it each time. The additional benefit is that you can store the ignore-on-commit list (if you want) in the repository.

I do this for some files which are constantly regenerated but rarely actually changed by hand. For instance I add revision number to my config files on specific placeholders so files are changed on each commit, yet manual change is rare.

查看更多
时光乱了年华
3楼-- · 2019-01-02 17:24

This is late to the game, but I found the most awesome-est command line command for this problem. Done using bash. Enjoy.

svn status | grep -v excluding | sed 's/^A */"/g; s/$/"/g' | tr '\n' ' ' | xargs svn commit -m "My Message"

Ok, so here's an explanation of the command. Some things will need to be changed based on your use case.

svn status

I get a list of all the files. They'll all start with those status characters (?, !, A, etc). Each is on its own lines

grep -v excluding

I use grep to filter the list. It can either be used normally (to include) or with the -v flag (to exclude). In this case, it's being used to exclude, with a phrase "excluding" being what will be excluded.

sed 's/^. */"/g; s/$/"/g'

Now I remove the status character and whitespace at the beginning of each line, and then quote each line, using sed. Some of my filenames have spaces in them, hence the quoting.

tr '\n' ' '

Using tr, I replace all newlines with spaces. Now my entire list of files to commit is on one line.

xargs svn commit -m "My Message"

Lastly, I use xargs to execute my commit command with the message. It does the commit, and drops my quoted file list as the last argument.

The result is that everything ultimately works the way that I want it to. I still kind of hate svn for forcing me to jump through these goddamn hoops, but I can live with this. I guess.

查看更多
美炸的是我
4楼-- · 2019-01-02 17:29

svn:ignore is your answer.

Example:

$ svn propset svn:ignore -F .cvsignore .
property 'svn:ignore' set on '.'
查看更多
长期被迫恋爱
5楼-- · 2019-01-02 17:31

Conflicted files are not allowed to be committed. You can take advantage of this to keep your private changes out of the repository. This works best with a small number of files.

To get a conflict for a-file, your working copy (WC) does not have the up to date a-file from the repository, and that the a-file in your WC has changes that are in the same location as changes in the repository (changes that you didn't update to yet). If you don't want to wait for the conditions above you can create a conflict for a-file like this:
In working copy 1 (WC1), add a line of text to the top of a-file, such as "make a conflict here". Use the necessary syntax so that you don't break the repository. Commit a-file from WC1. In WC2, add a different line of text to the top of a-file, like "i want a conflict". Update from WC2, and now a-file should be in conflict.

查看更多
美炸的是我
6楼-- · 2019-01-02 17:34

I came to this thread looking for a way to make an "atomic" commit of just some files and instead of ignoring some files on commit I went the other way and only commited the files I wanted:

svn ci filename1 filename2

Maybe, it will help someone.

查看更多
孤独总比滥情好
7楼-- · 2019-01-02 17:34
svn propset "svn:ignore" "*.xml" .

the *.xml is the pattern of files to ignore; you can use directory names here as well.

查看更多
登录 后发表回答