对于已经git跟踪的文件,我们可以提交更改而不在GIT中添加更改吗? [英] For already git tracked file, can we commit changes without adding them in GIT

查看:76
本文介绍了对于已经git跟踪的文件,我们可以提交更改而不在GIT中添加更改吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的本​​地存储库中有GIT跟踪的文件.现在,如果我对该文件进行更改,则标准过程如下.

例如对于文件demo.txt,

  git add demo.txtgit commit -m更改已完成";demo.txt 

但是,我能够直接提交这些更改而无需暂存它们.例如用于GIt跟踪文件demo.txt

  git commit -m已完成更改";demo.txt 

这将提交更改.

对此我们有什么解释

解决方案

对此我们有什么解释

是的,我们愿意.它称为文档.让我们一起阅读吧?

可以通过多种方式指定要提交的内容:...

  • 通过列出文件作为commit命令的参数...,在这种情况下,提交将忽略索引中暂存的更改,而是记录列出的文件的当前内容(Git必须已经知道)li>

这正是您正在做的.您是在 commit 命令中明确地说出文件名.这会导致git跳过整个 add 阶段,只是假装 demo.txt 是唯一添加到索引中的内容,并从中形成提交./p>


这实际上是一个非常酷的小捷径,因为它不会否​​定索引.索引仍然坐在那里,可能充满其他东西,等待您从中形成 next 提交(如果您愿意).想象一下这种情况:

  1. 您编辑并添加,编辑并添加,编辑并添加...

  2. 您拍了一下额头.哦,该死!我已经建立了索引,但是我真正想做的是在这里提交这两个文件,而不是索引中的所有内容!

  3. 现在,您可能在想,我想我必须以某种方式使用 stash .但不是!您使用了快捷方式,看得出来,您已经做到了.并且索引保持其完整性,您可以继续工作.

I have file which tracked by GIT in my local repository. Now, if I make changes in that file, standard process is as follows.

e.g. for file demo.txt,

git add demo.txt
git commit -m "changes done" demo.txt

HOWEVER, I am able to directly commit those changes without staging them. e.g. for GIt tracked file demo.txt

git commit -m "changes done" demo.txt 

this will commit changes.

Do we have any explanation for this

解决方案

Do we have any explanation for this

Yes, we do. It's called the documentation. Let's read it together, shall we?

The content to be committed can be specified in several ways: ...

  • by listing files as arguments to the commit command..., in which case the commit will ignore changes staged in the index, and instead record the current content of the listed files (which must already be known to Git)

That is exactly what you are doing. You are saying the name of the file explicitly in the commit command. This causes git to skip right past the whole add phase and just pretend that demo.txt is the only thing added to the index, and to form the commit from that.


This is actually a really cool little shortcut, because it doesn't negate the index. The index is still sitting there, possibly full of other stuff, waiting for you to form the next commit from it (if you like). So imagine this scenario:

  1. You edit and add, edit and add, edit and add...

  2. You slap your forehead. Oh, darn! I've formed my index, but what I really want to do is commit this couple of files here, not what's in the index at all!

  3. Now, you might be thinking, I guess I'll have to use stash in some way. But no! You use your shortcut and behold, you've done exactly that. And the index maintains its integrity and you can go on working.

这篇关于对于已经git跟踪的文件,我们可以提交更改而不在GIT中添加更改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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