0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ファイルを追加する、ステージの状態を見る

Posted at

ファイルをさらに追加する

ファイルをステージする

git add ファイル

演習1

以下の内容をもつファイルhello.txtを作業ツリーに作り、ステージしよう。まだコミットしない。

*********@mbp training % vim hello.txt
*********@mbp training % git add hello.txt
*********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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

これでステージされたと思う。

どのファイルを新たにステージしたかを見る

git status

HEADが指すコミットと、ステージと、作業ツリーの差を表示する

実際使ってみた。

*********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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

コミットするものがない場合は
nothing to commit (working directory clean)
と表示される。

クリーン(clean)

未保存の変更がない

ダーティ(dirty)

未保存の変更がある

同じファイルを新たにステージに加えた状態

*********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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

その中の

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   hello.txt

前の演習の時に2度ステージ(内容は違う)してしまったからこう表示されたのか。
Changes to be committed:

git statusはHEADとステージと作業ツリーを比べて状態を表示する
しかし
操作そのものを追跡しているわけでない。  

gitの管理下にないファイル

*********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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

この場合は
.gitignoreというファイルが管理下には言いていない。
追跡されていないファイルとして表示される

演習 

本文にあるようにREADMEを修正して、新しいhello.txtとともにコミットしよう。その各段階でgit statusを出力しよう。

*********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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
***********@mbp training % vim README.md

***********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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:   README.md

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

修正した後はmodified(変更された)と書かれてある。

**********@mbp training % vim hello.txt

**********@mbp training % git commit README.md
[master eba864f] 演習課題 RAEDME.mdを修正
 1 file changed, 3 insertions(+), 1 deletion(-)
***********@mbp training % git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   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
***********@mbp training % git commit hello.txt
[master 7143601] 演習課題 hello.txtを新しくコミットする
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt

**********@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

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")

なるほど一度もコミットされてないファイルは途中で中身が変更されてもnew file:扱いなのか。

*********@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")
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?