3

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.)

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

the command you suggested is almost the same as typing it in two lines. But as you mentioned, it is by design that these two commands cannot be combined. I frequently create a new file, add some code and submit to the repo. And it's just little tedious to do that every time. I think GIT has -am to do so, as far as I know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.