Git - 自动跟踪目录中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10758904/
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
Git - Automatically track all files in a directory
提问by Chris Dutrow
Possible Duplicate:
git add -A, git commit in one command?
If I understand correctly, when new files are added to a directory when using git, I have to call more than one command to make sure that the files are committed:
如果我理解正确,当使用 git 将新文件添加到目录时,我必须调用多个命令以确保文件已提交:
git add <directory name>
git commit -m 'commit comment'
This doesn't sound right because I know I (and many other people) will forget to call git add <directory name>
and then end up with a project that is missing all the new files that were created. It seems that I should be able to commit the entire directory, including any and all new files, in one command without having to specify in a previous command to add all new files to the commit. How do I do this?
这听起来不太对,因为我知道我(和许多其他人)会忘记调用git add <directory name>
,然后最终得到一个缺少所有创建的新文件的项目。似乎我应该能够在一个命令中提交整个目录,包括任何和所有新文件,而无需在前一个命令中指定将所有新文件添加到提交中。我该怎么做呢?
采纳答案by Olivier Refalo
get G2at https://github.com/orefalo/g2
在https://github.com/orefalo/g2获取G2
G2 will help you learn the git command line by providing easy to use macros.
G2 将通过提供易于使用的宏来帮助您学习 git 命令行。
the command is g freeze -m "commit msg"
.
命令是g freeze -m "commit msg"
.
It works with additions, deletions and changes. you are freezing a state.. which should have been the way to be from day one.
它适用于添加、删除和更改。你正在冻结一个状态......这应该是从第一天开始的方式。
回答by simont
git commit -a
will commit all files known to git:
git commit -a
将提交 git 已知的所有文件:
-a, --all Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about are not affected.
-a, --all Tell the command to automatically stage files that have been modified and deleted, but new files you have not told git about are not affected.
If you want to make sure you're committing everything you want to be, you can use git-status
prior to a git-commit
, to see the files that are staged for committing.
如果你想确保你提交了你想要的一切,你可以git-status
在 a 之前使用git-commit
,查看为提交而暂存的文件。
git
uses a two-stage process to get changes from the working directory
into the repository
. A catch-all approach like git commit -a
willwork, but it will lead to messy, non-atomic commits. I would advocate for smaller, focused commits, rather than using a catch-all approach such as you are searching for.
git
采用了两阶段的过程来从变化working directory
到repository
。一个综合性的做法一样git commit -a
会工作,但它会导致杂乱,非原子提交。我会提倡较小的、集中的提交,而不是使用您正在寻找的包罗万象的方法。
This doesn't sound right because I know I (and many other people) will forget to call git add...
这听起来不对,因为我知道我(和许多其他人)会忘记调用 git add ...
git-status
is your friend :)
git-status
是你的朋友 :)
Note: git-add
does notadd files to the repository. git commit
commits things from the staging area
the repository
, notfrom the working area
. This might seem odd at first, but gives much greater flexibility. See another answerfor more information.
注意:git-add
不不将文件添加到资料库。git commit
从承诺的事情staging area
了repository
,不从working area
。乍一看这似乎很奇怪,但提供了更大的灵活性。有关更多信息,请参阅另一个答案。