簡體   English   中英

在 Git 中的一次提交中進行多項更改?

[英]Staging several changes in one commit in Git?

我正在觀看 Coursera 的 git 課程。

有一部分我不明白講師在哪里說過,“分階段和提交之間的單獨步驟允許我們在一次提交中進行多個更改。”

我很困惑,因為據我了解,一個提交命令會提交多個更改,而不是進行多個更改。 如果我想進行更改,我是否必須調用 git add 命令?

請讓我知道我錯過了什么。

暫存和提交之間的單獨步驟允許我們在一次提交中暫存多個更改。

它強調分階段(即add命令)和提交是不同的步驟,它允許在您提交之前進行多個分階段(如果需要)。

但是您確實可以將所有內容暫存,然后只提交一次。 沒有說(甚至暗示)提交階段的事情。 句子的主語是單獨的步驟

有什么不清楚的?

如果我想進行更改,我是否必須調用 git add 命令?

如果您想暫存然后提交所有更改,您可以:

git commit -am "all changes"

但是,如果您想提交一些更改,您可以通過首先將文件添加到緩存來准備下一次提交。
請參閱“ GitHowTo:暫存和提交

git 中的暫存步驟允許您繼續對工作目錄進行更改,當您決定要與版本控制交互時,它允許您記錄小提交中的更改。

Suppose you have edited three files ( a.html , b.html , and c.html ).
After that you need to commit all the changes so that the changes to a.html and b.html were a single commit, while the changes to c.html were not logically associated with the first two files and were done in a separate commit.

理論上,您可以執行以下操作:

 git add a.html git add b.html git commit -m "Changes for a and b"

然后:

 git add c.html git commit -m "Unrelated change to c"

將暫存和提交分開,您有機會輕松自定義提交的內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM