236

Is there any way to commit only a list of specific files (e.q. just one of the list of files that SVN wants to commit).

I'm working on MAC OS X under Terminal, without any UI.

Fritz
  • 1,293
  • 15
  • 27
0100110010101
  • 6,469
  • 5
  • 33
  • 38

7 Answers7

353

Sure. Just list the files:

$ svn ci -m "Fixed all those horrible crashes" foo bar baz graphics/logo.png

I'm not aware of a way to tell it to ignore a certain set of files. Of course, if the files you do want to commit are easily listed by the shell, you can use that:

$ svn ci -m "No longer sets printer on fire" printer-driver/*.c

You can also have the svn command read the list of files to commit from a file:

$ svn ci -m "Now works" --targets fix4711.txt
unwind
  • 391,730
  • 64
  • 469
  • 606
  • 1
    so, basically, i should name the files explicitly? i can't just say don't touch this particular file? – 0100110010101 Oct 04 '09 at 11:26
  • 16
    you could do: svn st | cut -c 9- > targets.txt , then edit the targets.txt file to remove the specific file and use the --targets parameter to specify the filelist. – rein Nov 21 '12 at 00:45
  • 18
    I think my new challenge is to *create* a bug which sets the printer on fire. – James Webster May 19 '15 at 13:39
  • 3
    It is pathetic and ridiculous alike. No staging area. ```svn add``` is used to add files to repositories. – Kandinski Feb 26 '16 at 08:32
79

Use changelists. The advantage over specifying files is that you can visualize and confirm everything you wanted is actually included before you commit.

$ svn changelist fix-issue-237 foo.c 
Path 'foo.c' is now a member of changelist 'fix-issue-237'.

That done, svn now keeps things separate for you. This helps when you're juggling multiple changes

$ svn status
A       bar.c
A       baz.c

--- Changelist 'fix-issue-237':
A       foo.c

Finally, tell it to commit what you wanted changed.

$ svn commit --changelist fix-issue-237 -m "Issue 237"
jcwenger
  • 11,383
  • 1
  • 53
  • 65
  • +1 for on point answer. Changelists are really the way to go! – Miro Markaravanes Sep 24 '14 at 04:40
  • 1
    If you want to add new directories to a changelist, don't forget to use svn add first, then use `svn changelist fix-issue-237 --recursive path/to/directory` – Fabian Schmengler Jul 08 '15 at 06:23
  • Actually changelists cannot be used with new directories.... "Subversion doesn't currently support the use of changelists with directories. " – Fabian Schmengler Jul 08 '15 at 06:55
  • 1
    @fschmengler: SVN is a horrible tool. I was just trying to make the best of the bad job it does. Switch to git. :P – jcwenger Jul 09 '15 at 13:59
  • 12
    I switched to Git many years ago and never looked back. Was forced to use svn again for a client, it feels like running with ball and chain at both legs – Fabian Schmengler Jul 09 '15 at 14:06
  • Almost like Git's staging area! Only so much more cumbersome. But really good to know if one's forced to work with arcane tools like Subversion. – anothernode Jul 10 '17 at 16:32
42

You basically put the files you want to commit on the command line

svn ci file1 file2 dir1/file3
Wienczny
  • 3,958
  • 4
  • 30
  • 35
  • 1
    so, basically, i should name the files explicitly? i can't just say don't touch this particular file? – 0100110010101 Oct 04 '09 at 11:30
  • 2
    if run without arguments svn commits all changed files if run with a file as argument this file is commited if run with a directory all changed files in the directory are commited – Wienczny Oct 04 '09 at 14:21
23

Due to my subversion state, I had to get creative. svn st showed M,A and ~ statuses. I only wanted M and A so...

svn st | grep ^[A\|M] | cut -d' ' -f8- > targets.txt

This command says find all the lines output by svn st that start with M or A, cut using space delimiter, then get colums 8 to the end. Dump that into targets.txt and overwrite.

Then modify targets.txt to prune the file list further. Then run below to commit:

svn ci -m "My commit message" --targets targets.txt

Probably not the most common use case, but hopefully it helps someone.

Eric
  • 422
  • 3
  • 7
10

Besides listing the files explicitly as shown by unwind and Wienczny, you can setup change lists and checkin these. These allow you to manage disjunct sets of changes to the same working copy.

You can read about them in the online version of the excellent SVN book.

Community
  • 1
  • 1
sbi
  • 219,715
  • 46
  • 258
  • 445
7

try this script..

#!/bin/bash
NULL="_"
for f in `svn st|grep -v ^\?|sed s/.\ *//`; 
     do LIST="${LIST} $f $NULL on"; 
done
dialog --checklist "Select files to commit" 30 60 30 $LIST 2>/tmp/svnlist.txt
svn ci `cat /tmp/svnlist.txt|sed 's/"//g'`
pmod
  • 10,450
  • 1
  • 37
  • 50
2

I make a (sub)folder named "hide", move the file I don't want committed to there. Then do my commit, ignoring complaint about the missing file. Then move the hidden file from hide back to ./

I know of no downside to this tactic.