是否可以跳过暂存区并(也)将未跟踪的新文件提交到 git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16068968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to skip the staging area and (also) commit untracked, new files to git?
提问by nutty about natty
Is it possible to skip the staging areaand (also) commit untracked, new filesto git in a single built-in, command-line command ? If not, what are the alternatives ?
是否可以在单个内置命令行命令中跳过暂存区并(也)将未跟踪的新文件提交到 git ?如果没有,有什么替代方案?
http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository
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'
为 git commit 命令提供 -a 选项会使 Git 在提交之前自动暂存已跟踪的每个文件,让您跳过 git add 部分:
$ git commit -a -m 'added new benchmarks'
Thanks.
谢谢。
采纳答案by nutty about natty
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 (withoutcustom aliases): Just use a semicolon ;
and it'll work as a one-liner:
这对大师来说似乎微不足道,但对我来说是一个小启示(我承认) - 至少我现在第一次使用它并且它有效(没有自定义别名):只需使用分号;
它就会起作用作为单线:
git add --all; git commit -m "some informative commit message"
git add --all; git commit -m "some informative commit message"
回答by Klas Mellbourn
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:
将此添加到.gitconfig:
[alias]
commituntracked = "!git add -A; git commit"
Then you can do
然后你可以做
git commituntracked
回答by jthill
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.
是的。至少有两种主要方法可以做到这一点。首先,您不必使用“the”暂存区,您可以拥有任意数量的暂存区——随心所欲地设置GIT_INDEX_FILE=/path/to/private/index
和执行;其次,您可以直接自己构建提交。这甚至不难。
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
.
Git 的存储库核心处理 blob、树和提交对象(这里也不太相关,注释和带注释的标签)。转储对象的 git 命令是git cat-file -p
.
A blob is just a bag-o-bits. Add one to the repository with git hash-object -w
filename
, 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 -p
mom
-p
dad sometree
, set some environment variables, and feed it a commit message on stdin.
一个 blob 只是一个 bag-o-bits。使用 将一个添加到存储库git hash-object -w
filename
,它将打印该文件中 blob 的 ~true name~ 并将 blob 添加到 repo。树将对象与文件系统名称联系起来。添加一个到存储库git mktree
;看看喂它什么,用例如打印一棵树git cat-file -p HEAD^{tree}
。添加一个提交到存储库git commit-tree
,基本上,你说,设置一些环境变量,并在标准输入上提供一个提交消息。git commit-tree -p
mom
-p
dad sometree
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 tutorialis a good overview.
这才是真正需要的;如果你想进一步进入切片和树木和分期切割read-tree
和write-tree
是非常有用的,如果这是在所有吸引你的git的核心教程是一个很好的概述。
回答by Mahmoud Badri
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.
请注意,您仍然需要添加新的未跟踪文件。