为什么我必须使用

为什么我必须使用

本文介绍了为什么我必须使用“git commit -a”而不仅仅是“git commit”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用git clone [url here]从GitHub下载了一个存储库。

/ p>

我做了一些更改,试图用git commit提交它们。这似乎并没有将更改推送到我的本地存储库(在本地目录.git)中,并且建议我使用git commit -a来代替。



我想知道为什么我必须将-a附加到git commit,以及git中的stage和commit之间的区别是什么?

解决方案

Git有一个临时区域,默认情况下 git commit 只会提交添加到该临时区域的数据, -a 切换提交所有未提交的工作副本自动更改。



暂存区域的想法是您可能不想一次提交所有更改。如果是这样的话,你需要 git add 你想提交的文件 - 或者如果你希望它更好 - 你可以在 git add -p 中选择一个文件内的一些改变。



一个很好的解释加上一张图片,显示了它在GitHub Git教程中的基本工作原理:


I'm trying to wrap my head around the intricacies of Git.

I pulled down a repository from GitHub using "git clone [url here]".

I made some changes, the tried to commit them with "git commit". This didn't seem to push the changes into my local repository (in local dir ".git), and it recommended that I use "git commit -a" instead.

I'm wondering why do I have to append "-a" to the "git commit", and whats the difference between "stage" and "commit" in git?

解决方案

Git has a staging area. By default git commit only commits data added to that staging area. The -a switch commits all uncommitted changing from the working copy itself.

The idea of the staging area is that you might not want to commit all changes at once. If that's the case you'd git add the files you want to commit - or if you want it even more fine-grained, you'd git add -p and select only some changes within a file to be commited.

There's a nice explanation plus an image showing how it basically works in the GitHub Git tutorial: http://web.archive.org/web/20130519130755/http://learn.github.com/p/normal.html

这篇关于为什么我必须使用“git commit -a”而不仅仅是“git commit”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 04:03