【Git】3つの領域とファイルの状態(trackedとuntracked)

  • このエントリーをはてなブックマークに追加

3つのステージとファイルの状態(trackedとuntracked)は重要である。
新規で追加されたファイルはWorking directoryのuntrackedファイルになる。
ローカルリポジトリに存在するファイルを修正するとWorking directoryのtrackedファイルになる。
この挙動がとても重要。必ず覚える必要がある。



「git status」コマンドを実行する。
ローカルリポジトリに既に存在するファイルを修正し、ローカルリポジトリに存在しないファイルを新規で追加すると次のようになる。

ローカルリポジトリに既に存在するファイルを変更した場合
Changes not staged for commit(コミット用にステージングされていない変更点)
README.md

ローカルリポジトリに存在しないファイルを新規で追加した場合
Untracked files(Working directoryに存在するuntrackedファイル)
.gitattributes
LICENSE
LocalTime.js
LocalTime_sample.js
package.json

no changes added to commit(コミット用に追加された変更点なし)
これに該当するファイルは存在しない。


$ git status
On branch main
Your branch is up to date with 'origin/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 directory)
        modified:   README.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitattributes
        LICENSE
        LocalTime.js
        LocalTime_sample.js
        package.json

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

Working directoryに存在するuntrackedファイルは「rm」コマンドで削除すること。

他の英語のメッセージも日本語に訳しておく。次の通りである。

use “git add …” to update what will be committed
(コミットされる内容を更新するために、「git add …」を使用せよ。)

use “git restore …” to discard changes in working directory
(working directoryの変更を破棄するために、「git restore …」を使用せよ。)

use “git add …” to include in what will be committed
(コミットされる内容に含めるために、「git add …’」を使用せよ。)

no changes added to commit (use “git add” and/or “git commit -a”)
(コミットするために追加された変更はなし。「git add」および/または「git commit -a」を使用せよ。)

  • このエントリーをはてなブックマークに追加

SNSでもご購読できます。

コメントを残す

*