Question

Is it possible to skip the staging area and (also) commit untracked, new files to git in a single built-in, command-line command ? If not, what are the alternatives ?

http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository

Providing the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the git add part:

$ git commit -a -m 'added new benchmarks'

Thanks.

Was it helpful?

Solution 2

This might seem quite trivial for the gurus, but is a minor revelation to me (I admit) - at least I just used it for the first time now and it works (without custom aliases): Just use a semicolon ; and it'll work as a one-liner:

git add --all; git commit -m "some informative commit message"

OTHER TIPS

Using a single, built-in, command-line command? No.

Using two commands:

git add -A
git commit

Using a custom alias:

Add this to .gitconfig:

[alias]
   commituntracked = "!git add -A; git commit"

Then you can do

git commituntracked

Yes. There are at least two major ways of doing that. First, you don't have to use "the" staging area, you can have as many staging areas as you like -- set GIT_INDEX_FILE=/path/to/private/index and do as you please; second you can construct commits yourself, directly. It isn't even hard.

Git's repository core deals with blob, tree, and commit objects (also, not so relevant here, notes and annotated tags). The git command to dump objects is git cat-file -p.

A blob is just a bag-o-bits. Add one to the repository with git hash-object -wfilename, it'll print the ~true name~ of the blob in that file and add the blob to the repo. A tree ties an object to a filesystem name. Add one to the repository with git mktree; to see what to feed it, print a tree with e.g. git cat-file -p HEAD^{tree}. Add a commit to the repository with git commit-tree, basically, you say git commit-tree -pmom-pdad sometree, set some environment variables, and feed it a commit message on stdin.

That's really all that's necessary; if you want to get further into slicing and dicing with trees and staging read-tree and write-tree can be very useful, if this is at all attractive to you the git core tutorial is a good overview.

Using the command below skips the staging area and commits directly from the working directory.

git commit -a

Note that you still need to add new untracked files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top