简体   繁体   中英

SVN Add and Commit File in a single Command Line

How can I add and commit a single file in a single command?

Currently, I am doing,

svn add test.txt
svn commit test.txt -m "Added a new file"

Is there a way to do this in a single command? I am not trying to use this to add and commit all files, just a single file.

(I have spent some time on searching this, but could not find a reasonable solution.)

If you want to do it with a single "command" you can use something such as:

svn add test.txt && svn commit test.txt -m "Added a new file"

Using the & or && operators, you can string together multiple commands via the command line. The difference between the single and double ampersands is that the second command will only run if the first command exits successfully (if that command returns a 0).

If you're just asking if subversion will allow you to commit straight into the repository without adding the item first, the answer is no, and it's by design. You have to tell subversion that test.txt is an item you'd like to keep under version control.


The idea behind having to doing an add before a commit is that you may want to commit all of your changes in a project that are currently under version control. Therefore, you can commit an entire folder if you'd like. However, if you're a developer there a lot of times where you'll be generating binary files that DO NOT need to go into the repository because they are dynamically generated, yet, you can still run commits on that folder and commit all of your changes as opposed to doing every file individually.

It can be thought of as a sanity check for yourself, to ensure that what you're committing to the repository, is actually what you want in the repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM