教我混帐提交 [英] Teach me git commit

查看:157
本文介绍了教我混帐提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不要完全理解git commit。

自从我使用git和所有这些git与 -a,-m,新文件,未跟踪等使我完全困惑。 Tortoisegit现在正在拯救我,但我想了解其中的本质,并以一种非常简单的方式使用它。

当我在git命令行中时,选择性提交某些文件并将其余提交给其他提交者是相当困难的。我如何使这容易?

解决方案

这很简单。您需要首先添加所需的更改索引

  git add file1 file2 

然后

  git commit 

如果您删除了一个文件,那么add会这样做。添加意味着添加更改即使是删除。



如果您想添加所有更改:

  git add -A 

上的 -a 参数表示添加跟踪文件的所有更改并提交它们。因此

  git commit -a 

不会提交您创建的新文件。您必须明确地添加此项。



-m 参数可让您避免打开编辑器编辑您的提交消息,并使用您在 -m 选项后面输入的内容:

  git commit -m使用此信息并且不要打开编辑器

有时候这不是一个好主意。如果您只是尝试合并并发生冲突,那么一旦解决冲突并提交,git就会为您缓存一条非常好的消息。因此, git commit 更好。



要有选择地添加文件,请使用git add上的patch修饰符:

  git add -p 

现在会提示您关于这些文件。这是非常强大的,因为你也可以指定部分文件,或者编辑你想要添加到索引的内容。如果你想要一些不是tortoisegit的gui帮助(避免使用windows shell集成),可以使用<$($ g

c $ c> git gui 。



以下是解释索引(或分段文件)的图表:





(来自 http://progit.org/book/ch2- 2.html



希望这有助于。


I don’t understand git commit at all.

It’s been a week since I’ve been using git and all these git with –a, -m, new files, untracked etc is making me totally confused. Tortoisegit is saving me for the moment, but I would like to understand the essence and use it in a way it’s totally easy.

When I am in the git command line, it’s rather difficult to selectively commit some files and keep the rest for another commit. How do I make this easy?

解决方案

It is quite simple. You need to add the changes that you want to the index first:

git add file1 file2

then

git commit

if you removed a file, the add does that. Add means "add the change" even though it is a removal.

If you want to add all changes:

git add -A

The -a parameter on commit says to add all changes of tracked files and commit them. So

git commit -a

will not commit a new file you created. You must explicitly add this.

The -m parameter allows you to avoid opening the editor to edit your commit message and use what you put in following the -m option:

git commit -m "Use this message and don't open the editor"

Sometimes this is not a good idea. If you just tried a merge and had conflicts, git caches a very nice message for you once you resolve the conflicts and commit. So there a git commit is better.

To selectively add files, use the patch modifier on git add:

git add -p

This will now prompt you about the files. This is quite powerful as you can also specify parts of files, or alternatively edit what you want to add to the index. A git commit will only add those.

If you want some gui help that is not tortoisegit (avoid windows shell integration), use git gui.

Here is a diagram explaining the index (or staged files):

(from http://progit.org/book/ch2-2.html)

hope this helps.

这篇关于教我混帐提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆