LoginSignup
0
0

More than 1 year has passed since last update.

一度ステージした内容を変える

Last updated at Posted at 2022-07-05

一度ステージした後別の内容に修正してステージしてコミットしたくなった時は
git addでもう一度ステージし直す。

**********@mbp training % git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   .idea/workspace.xml
	modified:   hello.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore

no changes added to commit (use "git add" and/or "git commit -a")

ファイルが変更(HEADとステージの差)、変更がステージされていない(ステージと作業ツリーの差)

Changes not staged for commit:

「ファイルが変更されている」かつ「変更がステージされていない」ファイルがある場合に表示されます。
出典 https://atmarkit.itmedia.co.jp/ait/articles/1604/26/news019_3.html

Untracked files:

気づき

gitとはステージされることで追跡されるんだな。(今更)

演習

hello.txtについて、HEADとステージ、そしてステージと作業ツリーの内容が違う状態を作り、git statusの出力を見てみよう。

HEADとステージの内容の違い

***********@mbp training % git status
On branch master
c
  (use "git restore --staged <file>..." to unstage)
	modified:   hello.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   .idea/workspace.xml

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore

これでHEADとステージの違いを作ったと思っている。

Changes not staged for commit:
既にGitが変更を追跡しているファイルに対する変更をステージングエリアに追加しました。

新しいファイルの追跡
新しいファイルの追跡を開始するには git add コマンドを使用します。
出典 https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E5%9F%BA%E6%9C%AC-%E5%A4%89%E6%9B%B4%E5%86%85%E5%AE%B9%E3%81%AE%E3%83%AA%E3%83%9D%E3%82%B8%E3%83%88%E3%83%AA%E3%81%B8%E3%81%AE%E8%A8%98%E9%8C%B2#:~:text=%E3%81%AB%E3%81%97%E3%81%BE%E3%81%97%E3%82%87%E3%81%86%E3%80%82-,%E6%96%B0%E3%81%97%E3%81%84,-%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E8%BF%BD%E8%B7%A1

ステージと作業ツリーの内容の違い

***********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   hello.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   .idea/workspace.xml
	modified:   hello.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.gitignore

modified: hello.txtでステージとの違いを出したと思う。

その状態で、git diffgit diff ---satagedgit diff HEADの出力を比べてみよう。

git diff

.
.
.
diff --git a/hello.txt b/hello.txt
index ******************:
--- a/hello.txt
+++ b/hello.txt
@@ -1,4 +1,4 @@
 Hello!
 I am a student.
-hogehoge!!
+hogehogehogehoge!!

git diff ---sataged

************:@mbp training % git diff --staged
diff --git a/hello.txt b/hello.txt
index *********************
--- a/hello.txt
+++ b/hello.txt
@@ -1,3 +1,4 @@
 Hello!
 I am a student.
+hogehoge!!

まだコミットしていない状態

git diff HEAD

.
.
.
diff --git a/hello.txt b/hello.txt
index ****************
--- a/hello.txt
+++ b/hello.txt
@@ -1,3 +1,4 @@
 Hello!
 I am a student.
+hogehogehogehoge!!

作業ツリーとHEADの間ではhello.txtがhogehogehogehoge!!と変更している。
ことがわかる。
まだコミットされていない。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0