git status:作業ディレクトリの状態
作業ツリーとインデック
スの状態を表示
作業ツリー
で変更され
ているファ
イル
インデック
スにファイ
ルはない
インデック
スにある
ファイル
ステージング
すると
$ gitstatus
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working direc
modified: main.py
no changes added to commit (use "git add" and/or "git commit -a")
$
$ git add main.py
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: main.py
$
65.
git diff:コミット間差分
差分を見るコマンド 差分を取る2つのコミットID
コミットIDを指定しないと,
作業ツリーとインデックスの
差分を表示
$git diff eb88fd18 8b4c7528e
diff --git a/main.py b/main.py
index 1790121..6a41df2 100644
--- a/main.py
+++ b/main.py
@@ -15,7 +15,7 @@ def myfunc_4(a):
def main():
a = [1, 2, 3, 4, 5]
for _ in range(100):
- myfunc_2(a)
+ myfunc_4(a)
for _ in range(300):
myfunc_3(a)
$ git diff
diff --git a/main.py b/main.py
index 3e3af03..2f991d6 100644
--- a/main.py
+++ b/main.py
@@ -1,7 +1,7 @@
def myfunc(x, y):
- z = 2 * x - y + 1
+ z = 2 * x - y + 2
return z
66.
git mv, gitrm:ファイルの操作
nファイルの操作はgitコマンドを使う
• それまでの履歴が失われてしまう
• 通常のmv, rmは使わずgit rm, git mvを使おう
$ mv main.py main2.py
$ git status
On branch main
Your branch is up to date with 'origin/main'.
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: main.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
main2.py
no changes added to commit (use "git add" and/or "git commit -a")
$ git mv main.py main2.py
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: main.py -> main2.py
通常のmv:git履歴が失われる git mv:git履歴が残る!
削除されている
新しいファイル
ができている
rename扱い!
67.
git mv, gitrm:ファイルの操作
nファイルの操作はgitコマンドを使う
• それまでの履歴が失われてしまう
• 通常のmv, rmは使わずgit rm, git mvを使おう
通常のrm:単に削除 git rm:削除してadd済み
$ rm main.py
$ git status
On branch main
Your branch is up to date with 'origin/main'.
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: main.py
$ git rm main.py
rm 'main.py'
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: main.py
削除されている
削除されてadd済みな
のでcommit可能