Is it possible to skip the staging area and (also) commit untracked, new files to git?

流过昼夜 提交于 2019-11-27 15:00:39

问题


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.


回答1:


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



回答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"




回答3:


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.



来源:https://stackoverflow.com/questions/16068968/is-it-possible-to-skip-the-staging-area-and-also-commit-untracked-new-files-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!