2017-01-17 10 views
1

ありがとう、この質問を参照してください。変更が既にステージに追加されている間に別の変更をコミットするにはどうすればよいですか?

変更を自動的にコミットするスクリプトを作成しています。

ステージに何らかの変更が既に追加されている場合、指定されたファイルの指定された行だけをコミットする方法はありますか?例えば

私は空白hoge.txtを持っています。

次に、いくつかの行を追加してコミットします。

diff --git a/hoge.txt b/hoge.txt 
index e69de29..b3c5a95 100644 
--- a/hoge.txt 
+++ b/hoge.txt 
@@ -0,0 +1,5 @@ 
+line1 
+line2 
+line3 
+line4 
+line5 

git statusこう述べています。そして、

On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    modified: hoge.txt 

、私はいくつかの行に、よりLINE0とLINE6を追加します。

diff --git a/hoge.txt b/hoge.txt 
index b3c5a95..6006aa3 100644 
--- a/hoge.txt 
+++ b/hoge.txt 
@@ -1,5 +1,7 @@ 
+line0 
line1 
line2 
line3 
line4 
line5 
+line6 

git status言う:

On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    modified: hoge.txt 

Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

    modified: hoge.txt 

、私は段階的な変更を加えることなく、段階的ではない変更をコミットしたいです。しかし、1行目から5行目までをステージングする必要があります。

git statusは言う:

On branch master 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    modified: hoge.txt 

git diff --cachedは言う:あなたがすることはできません

diff --git a/hoge.txt b/hoge.txt 
index 588aa45..6006aa3 100644 
--- a/hoge.txt 
+++ b/hoge.txt 
@@ -1,2 +1,7 @@ 
line0 
+line1 
+line2 
+line3 
+line4 
+line5 
line6 

答えて

1

...

"ステージ" ゾーンの目標は、すべてのファイルが含まれていることですあなた次のコミットが必要なので、ステージングされていないファイルからコミットを行うことはできません。

あなたは奇妙な何かをしたいが、何を行うことができますことは次のとおりです。

  1. はあなたの第一の変更を隠し:git add hoge.txt
  2. git stash
  3. あなたの第二の変化
  4. があなたのステージゾーンに追加してください
  5. あなたの仕事を約束:git commit -m 'myWork'
  6. 最初の変更を取り戻す:git stash pop

解決には葛藤がありますが、第1回の前に2回目の変更をコミットします。

+0

OH ...ご回答いただきありがとうございます。 –

関連する問題