60

I want subversion to commit a file even if it's unchanged. Is there a way to do this?

2
  • I assume there may be very rare situations where this is needed. But most of the time, it really should not be. Every revision in SVN contains a snapshot of every file in the repository. In a way, you DID commit your unchanged file in the last revision. You just committed no changes (because there were none).
    – Ben
    Nov 9, 2014 at 12:47
  • 1
    One situation where this is necessary is when you've switched the character encoding of an otherwise unchanged file. This goes undetected by (Tortoise, at least) SVN.
    – KlaymenDK
    Jan 19, 2016 at 9:47

12 Answers 12

73

If you want the file contents to remain unchanged (meaning that you can't merely change whitespace as johnstok suggested) you can always change one of the properties on the file.

eg.

svn propset dummyproperty 1 yourfile
svn commit yourfile

That will perform a commit without having to change the file.

Just make sure that you don't use one of the special svn: properties. Anything else should be ok.


Edit: A number of other posters have asked why someone would want to do this - presumably the people who have marked this answer down have also had the same concerns.

I can't speak for the original poster, but one scenario where I have seen this used is when attempting to automatically synchronise activities on a Visual Sourcesafe repository with a subversion repository.

16
  • 67
    @Chris Becke It really doesn't matter, does it? He has a need for it that others don't, apparently. We can either help him, or ignore the question. Some of the negative feedback I've seen here is ridiculous.
    – Chris
    Dec 21, 2008 at 14:04
  • 3
    In 9 out of 10 cases (which I routinely round up to "always" :-)) cases, the questioneer has tried to solve a problem, done it badly, is left with a more problems than when he started, and is asking for help to put out the fire.
    – JesperE
    Dec 21, 2008 at 17:56
  • 20
    I'll give you a reason: some doofus checked in the file while his system clock was set far into the future.
    – Joshua
    Jan 25, 2009 at 22:58
  • 14
    Use Case: A file (config, xml, etc.) is chosen as a canonical version beacon for other apps. It indicates that "the code queried represents version rXYZ in SVN". Using SVN's macros on commit ("$Rev: xxxxx $") would be ideal for these purposes, provided SVN would deign to update an unchanged file.
    – pcorcoran
    Apr 7, 2009 at 4:33
  • 2
    @Tom Brito: You can create any arbitrary property, so you're not restricted to the properties that are already in place. The only restriction is that subversion reserves properties starting with "svn:" for their own use. Other than that, and avoiding any properties specifically used in your project, you're free to create whatever you like. Take a look at "svn help propset" for some more details. Apr 1, 2010 at 1:58
6

As to answer why one would like to do forced commits. I've seen cases where someone used a commit message that was wrong or unclear. It's nice if you can perform a forced commit, where you can correct this mistake. That way the updated commit message goes into the repository, so it won't get lost.

3
  • Git has an easy way to amend commits. Doesn't svn have anything like that? That would be an easier and better way to fix wrong/misleading commit messages.
    – iconoclast
    Jul 6, 2010 at 15:07
  • 1
    Yes, you can edit commit messages in SVN, but that then applies to the full commit which may include numerous other files. Recommitting an unchanged file would still be useful when you want to provide a more clear commit message for a specific file which wouldn't be applicable to all of the files in the previous commit.
    – twm
    Oct 12, 2014 at 16:13
4

I frigged this by deleting then re-adding the offending file. Not the nicest way to do it, and it probably broke the revision history, but it suited my purposes.

Reason for wanting to do it: File was one of two executables built from the same source (with different #defines set). Minor change to source meant one had changed, one didn't. I wanted to record in the revision history that I had actually updated it to the latest version (even though there was no change).

Maybe Morten Holdflod Møller's point that "the file will still be a part of the new revision" would cover this indication, but I think a log of the unchanged file did not show comments for that revision.

3
  • Changing the source gives you the opportunity to state exactly what you did, i.e. that "change X caused binary Y to be recompiled, but binary Z did not change". By forcing a commit when there really was no change to binary Z might actually confuse people: "why, if there was no change to binary Z, did he commit a new revision of it?"
    – JesperE
    Oct 16, 2010 at 19:58
  • 1
    I use the TAGS directory for that. Sep 27, 2011 at 10:37
  • This is an ancient question and response, but I stumbled across it looking for something else so I want to point out that this WILL destroy all revisioning history for the file if you delete and re-ad it. Depending on what you are trying to accomplish there are probably better ways.
    – Bryan Shaw
    Aug 4, 2015 at 17:35
2

If it's a text file just add some whitespace, such as a line feed.

2

Answering some people questioning this should be possible: for some reason svn doesn't recognizes differences between doc files, so I would like to force commit as well!

I am now moving documentation from static dirs, to svn. files are like UG_v1.2, UG_v1.3 etc. So just to keep history, I take 1.2, remove version from the filename and add and commit it to svn. Then I take the ver from the second one, copy it over the first one and want to commit it and newer version. File size and creation date changes (not mentioning what's inside the doc), but svn claims it's perfectly the same file and disallows me to commit. When I manually change the doc, svn sees the different. The heck? :>

0

I don't think that's possible, but first of all why do you need to do that? If a file is unchanged it shouldn't be commited.

If you really want that file grouped with other files in a commit you could change something minor inside (add a space for example).

4
  • 1
    O'Reilly uses SVN to manage book sources. If you forget to add "orm:commitpdf" to the check-in comments, a book is not built to inspect (O'Reilly scans comments looking for the directive). So its a valid use case: how do I check something in so I can make the "orm:commitpdf" comment to have the book built. I'm facing that situation right no (hence the reason I landed on this page).
    – jww
    Sep 29, 2013 at 19:07
  • I see - in that case I guess a space added to the file will (should) not make a big difference and it would be easier than adding a property. By I would have used a property anyway for this, rather than the comment. Does this mean you have to remember to add this text every time you commit the file?
    – rslite
    Oct 5, 2013 at 10:49
  • "Does this mean you have to remember to add this text every time you commit the file?" - Yes.
    – jww
    Oct 5, 2013 at 17:19
  • "... in that case I guess a space added to the file will (should) not make a big difference and it would be easier" - Yes, the space appears easiest. Plus they use DocBook, so it harmless.
    – jww
    Oct 5, 2013 at 17:20
0

The reason why someone wants to commit unchanged file is misunderstanding of how to revert to a previous version of a file.

For example, one may revert the file index.html in the revision 680 by just updating it to a revision in the past, e.g. 650:

svn update index.html -r 650

but it does not solve the problem, because:

svn status -u index.html
        *      650   index.html
Status against revision:    680

svn clearly says that index.html is modified remotely and you can't commit it, i.e. it "thinks" that index.html is old and should be updated to a newer revision. So the next svn update will bring index.html back to the revision 680.

To really revert a file you should merge it in reverse order:

svn merge -r 680:650 index.html

and then commit it svn ci -m "Reverted to r650" index.html

1
  • 5
    Sergiy - someone may just want to commit something to trigger a hook on the server. Invoking the server's trigger has nothing to do with changing/reverting a file.
    – jww
    Sep 29, 2013 at 19:12
0

Ancient question, but here's one reason why someone would want to do this:

We use an svn "commit" to document the successful outcome of a code review. During the code review, a certain subset of files is examined (and potentially modified). But files that are found to pass the review as-is will remain unmodified.

The idea is to use the commit to document which files were reviewed. That should include the ones that were found to pass the review without any modifications. Hence the need to "re-commit" ("force-commit") them unmodified.

1
  • This would be a good example of why you would want to add a property to the file, maybe "Reviewed" which can be either "true" or "false". Then you could commit the files with only a property change.
    – JonS
    Jul 14, 2023 at 22:30
-1

Actually, I have come across a reason to do a force commit. This probably isn't best practice but we put Truecrypt (http://www.truecrypt.org/) volumes in SVN because we need to keep a tight security on some shell script as it contains sensitive information. When a Truecrypt volume is created, it's binary data stays the same no matter what you do with it. So in effect, I can change the contents of the volume but the volume never appears changed.

3
  • 4
    "When a Truecrypt volume is created, it's binary data stays the same no matter what you do with it." simply cannot be true. Either it's changed, or not. There is no magic involved. I'd recommend checking what you're actually trying to commit ;)
    – viraptor
    May 1, 2009 at 23:04
  • See here for how to handle this with TC: flickspin.com/en/information_technology/…
    – Nik
    Aug 3, 2010 at 9:19
  • 1
    do you have a warehouse full of identical backup tapes? but with different dates on them. I would be worried about this. "something wrong somewhere!" Sep 27, 2011 at 10:36
-1

Changing the property will NOT force the commit.

TortoiseSVN 1.4.5, Build 10425 - 32 Bit , 2007/08/26 11:14:13

0
-1

I have the same problem with a trueCrypt volume.

I added a new property (as suggested above) "forceCommit1" and them I was able to commit the volume file. but only the property was commited not the contents of the file.

I removed the file and added it again to the svn

-2

I thought you could do it from the command line?

svn ci -force <filename>

I don't have a repository here to check that on, so I might be wrong.

2
  • No. There is no --force option to ci.
    – richq
    Oct 31, 2008 at 11:02
  • the only right thing in this answer is that you are wrong! :) Sep 6, 2013 at 11:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.