亀の甲羅2

今日もまた朝とく起きて励まなん窓に明るきありあけの月

【Git】 現在のワークツリーの状態確認:git status

タダのメモ

目次

本文

1. 説明

現在のワークツリーで、ステージに上げられていないファイルがあるかどうか、コミットされていないファイルがあるか、pushしていないものがあるかなど状態を確認できる。

> git status

2. 実行例

◆ワークツリーに新しいファイルを作成した状態

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:                                       <--- 追跡していないファイルがあるよーー(新規追加されたファイル)
  (use "git add <file>..." to include in what will be committed)
        b_powershell-samplecode/only10000filescopy.ps1

nothing added to commit but untracked files present (use "git add" to track)


◆ステージに上げてから確認

myPC MINGW64 /Git/rep_learning (master)
$ git add b_powershell-samplecode/only10000filescopy.ps1 b_powershell-samplecode/only10000filescopy.ps1 

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:                                <--- コミットするべき変更があるよーー
m  1 # test comment
  (use "git restore --staged <file>..." to unstage)
        new file:   b_powershell-samplecode/only10000filescopy.ps1        <--- 新しいファイルだよー


◆コミットしてから確認

myPC MINGW64 /Git/rep_learning (master)
$ git commit -m 'test commit'
[master 3bdda50] test commit
 1 file changed, 18 insertions(+)
 create mode 100644 b_powershell-samplecode/only10000filescopy.ps1

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.               <--- commitしたけど、pushもしてねーー
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


◆pushしてから確認

myPC MINGW64 /Git/rep_learning (master)
$ git push

   3cace2d..3bdda50  master -> master

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.             <--- 最新の状態になったよーー

nothing to commit, working tree clean


◆ワークツリーのファイルを編集した状態

myPC MINGW64 /Git/rep_learning (master)
$ vi b_powershell-samplecode/only10000filescopy.ps1

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/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:   b_powershell-samplecode/only10000filescopy.ps1

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


◆ステージに上げた状態

myPC MINGW64 /Git/rep_learning (master)
$ git add b_powershell-samplecode/only10000filescopy.ps1

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:                                          <--- コミットされていない変更があるよ
  (use "git restore --staged <file>..." to unstage)
        modified:   b_powershell-samplecode/only10000filescopy.ps1


◆コミットしないで再度編集した状態

myPC MINGW64 /Git/rep_learning (master)
$ !v
vi b_powershell-samplecode/only10000filescopy.ps1

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:                                           <--- コミットされていない変更があるよ
  (use "git restore --staged <file>..." to unstage)
        modified:   b_powershell-samplecode/only10000filescopy.ps1

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:   b_powershell-samplecode/only10000filescopy.ps1


◆ステージに上げた状態

myPC MINGW64 /Git/rep_learning (master)
$ git add b_powershell-samplecode/only10000filescopy.ps1 

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:                                              <--- コミットされていない変更があるよ
  (use "git restore --staged <file>..." to unstage)
        modified:   b_powershell-samplecode/only10000filescopy.ps1


◆コミットした状態

myPC MINGW64 /Git/rep_learning (master)
$ git commit -m 'test commit 2'
[master e9862cb] test commit 2
 1 file changed, 5 insertions(+), 2 deletions(-)

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.            <--- コミットしたけどpushもしてね
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


◆pushした状態

myPC MINGW64 /Git/rep_learning (master)
$ git push

   3bdda50..e9862cb  master -> master

myPC MINGW64 /Git/rep_learning (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.                    <--- 最新の状態になったよ

nothing to commit, working tree clean