LoginSignup
0
0

【Git】git status で変更状況を確認する方法

Posted at

以前こんなツイートをしました。git add , git commit する前に git status コマンドを使用するまではわかったけどどうやって使うのかわからないと思います。なのでこの記事では git status の詳細を説明していきます。

普段はプログラミングや、フリーランスについて発信しています。 フォローする

変更状況を確認する

変更状況を確認するには git status コマンドを使います。

>_ コマンドライン

> git status

git status の使用方法

ワークツリーとステージの間で変更されたファイル「git add で追加してから変更したワークツリーのファイル

ステージとリポジトリの間で変更されたファイル「git commit で追加してからステージに追加されたファイル

それぞれを表示してくれます。

変更状況を確認

git addindex.html ファイルをステージに追加した状態で、git status コマンドを実行した場合

>_ コマンドライン

> git status

On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   index.html

では、index.html ファイルに少し変更を加えてから git status コマンドを実行してみましょう。

>_ コマンドライン

> git status

On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   index.html

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:   index.html

すると、ステージに追加されていない変更があるよ と表示されました。

どのファイルがというと、modified: index.html が変更されたよ と表示されているわけです。

では、このファイルを git add でステージに追加して git status で確認していきます。

>_ コマンドライン

> git add index.html

> git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   index.html

次に表示されているのが Changes to be committed: でこれはコミットするべき内容があるよ と表示されています。

どのファイルがというと、new file: index.html がコミットするべき内容だよ と表示されているわけです。

では次にこのファイルをコミットして確認していきましょう。

>_ コマンドライン

> git commit -m "statusコマンドの確認"
[master 0420876] statusコマンドの確認
 1 file changed, 2 insertions(+)
 create mode 100644 index.html

> git status
On branch master
nothing to commit, working tree clean

git commit でファイルをコミットして

git status で確認すると 現在コミットするべき変更は無いよ と表示されました。

このようにファイルを変更したら git status コマンドでなんのファイルが変更されたかを確認してから git addgit commit する癖をつけてください。

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