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.

[Git] 動作を試す 実行例6:statusで現在の作業フォルダ内の変更状況を見る

Last updated at Posted at 2023-04-28

Gitの動作を理解するために、Gitのコマンドを実際に試して、結果を見てみました。

1つの記事内で一連のGitコマンドが完結しているので、これら一連のコマンドを順に実行させて結果を見ることで、一連のGitの動作を実際に体感でき、一通り独習することが可能です。

※前回記事のリポジトリ状態からの続きになっています。

前回記事へ 目次へ:Git関連記事のまとめページ 次回記事へ

実行例

echo Sample-Added-14 >> test1.txt
echo Sample-Added-41 > test4.txt
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:   test1.txt

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

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

※状態表示を簡略化して表示
git status -s
↓
結果: 
 M test1.txt
?? test4.txt

git add *.txt
git status
↓
結果: 
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   test1.txt
        new file:   test4.txt

git status -s
↓
結果: 
M  test1.txt
A  test4.txt

git commit -m "message4"
↓
結果: 
[master 94996a0] message4
 2 files changed, 2 insertions(+)
 create mode 100644 test4.txt

git status
↓
結果: 
On branch master
nothing to commit, working tree clean

git status -s
↓
結果: 
(なし)

-----

dir /b
↓
結果: 
test1.txt
test2.txt
test4.txt

del test4.txt
dir /b
↓
結果: 
test1.txt
test2.txt

git status
↓
結果: 
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    test4.txt

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

git status -s
↓
結果: 
 D test4.txt

git add .
git status
↓
結果: 
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    test4.txt

※「git add .」により、削除したファイルも削除としてコミットされる予定との表示となる。

git status -s
↓
結果: 
D  test4.txt

※「git add .」操作の前の状態に戻す
git restore --staged .
git status
↓
結果: 
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    test4.txt

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

git status -s
↓
結果: 
 D test4.txt

※削除したファイルと同じ内容を書き込んで、手動で復元すると、
echo Sample-Added-41 > test4.txt
git status
↓
結果: 
On branch master
nothing to commit, working tree clean

環境

Windows 10、PortableGit-2.40.0-64-bitを使用、全てローカルPC上で実施、GitHub等は不使用。

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?