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?

gitのあれこれ

0
Posted at

はじめに

gitについての雑多な内容。後で体系化させます。

初期設定

必須項目

git config --global user.name "名前"
git config --global user.email "メールアドレス"

プロキシ設定(環境変数以外で行う場合)

git config --global http.proxy ${URL}:${port}

※https.proxyはありません。

設定の確認

git config --list

.gitkeepについて

gitは仕組み上ファイルのみが対象になるので、空のディレクトリは無視される。空のディレクトリも保持したい場合は、よく.gitkeepという空のファイルを置くというテクニックがある

用語

  • スナップショット(Snapshot): ある時点でのプロジェクト全体の状態を記録したもの
  • コミット(Commit): スナップショットに名前・説明・履歴情報を付けること
  • Working Directory: 今編集しているファイルたち
  • Staging Area: 次のコミット候補を置く場所
  • Index: Staging Areaの内部実装(.git/index)
  • Cache: Git内部や古い資料でIndexをさすことがある名称
  • Tree: Gitのオブジェクトでフォルダを示す
  • Blob: Gitのオブジェクトでファイルを示す
  • Working Tree: Working Directoryとほぼ同じだが、Commit対象のものに対して言う
  • Untracked: Gitがファイルをどのように認識しているかを示すもの。Gitがまだ管理していないファイルのこと
  • Tracked: Gitがファイルをどのように認識しているかを示すもの。Gitが管理しているファイルのこと
  • Unmodified:Gitがファイルをどのように認識しているかを示すもの。Trackedのうちコミット時から変更されていないファイルのこと(コミットと作業ファイルが一致している)
  • Modified:Gitがファイルをどのように認識しているかを示すもの。Trackedのうちコミット時から変更されているファイルでまだステージされていないもののこと
  • Staged:Gitがファイルをどのように認識しているかを示すもの。Trackedのうちコミット時から変更されているファイルでステージされたもの
  • HEAD: 現在どこ(Commit)を指しているかを記録する参照
  • Detached HEAD: HEADがブランチ以外を指している状態
  • Revision Parameters(リビジョンパラメータ):「どのコミット・ブランチ・履歴位置を指すのか」を指定する記法の総称

ステータスについて

Unmodified

HEAD = Index = Working Tree

Modified

HEAD = Index ≠ Working Tree

Staged

HEAD ≠ Index = Working Tree

※ステージ後にファイルを変更するとIndex と Working Treeは一致しなくなる

Revision Parameters(リビジョンパラメータ)について

名称 内容
HEAD 現在
HEAD~1 1つ前
HEAD~2 2つ前
main ブランチ先頭
feature ブランチ先頭
a1b2c3 特定コミット

git-resetについて

HEADを特定のCommitに動かす

git reset <commit>
git reset HEAD~1

次は使いませんgit-restoreを使いましょう

git reset [--soft | --mixed | --head] <commit>

git-restoreについて

IndexやWorking Treeのファイルのうち特定のものあるいは全部をあるTreeのものに回復させるコマンドである

# 特定のファイルに対してtreeをソースとしてIndexとWorking Treeを回復
git restore --staged --worktree --source=<tree> <pathspec>…
# 特定のファイルに対してtreeをソースとしてIndexのみ回復
git restore --staged --source=<tree> <pathspec>…
# 特定のファイルに対してHEADをソースとしてIndexとWorking Treeを回復
git restore --staged --worktree <pathspec>…
# 特定のファイルに対してHEADをソースとしてIndexのみ回復
git restore --staged <pathspec>…
# treeをソースとしてWorking Treeのみ回復
git restore --worktree --source=<tree>
# HEADをソースとしてWorking Treeのみ回復
git restore --worktree
# IndexをソースとしてWorking Treeを回復
git restore

git-diffについて

特定のファイルに対してcommit同士を比較

# commit1とcommit2の比較
git diff <commit1> <commit2> <path>
# Indexとcommitの比較
git diff --cached <commit> <path>
# IndexとHEADの比較
git diff --cached <path>
# IndexとWorking Treeの比較
git diff <path>

git-tagについて

# commitにタグをつける
git tag <tagname> <commit>
# HEADにタグをつける
git tag <tagname>
# タグ削除
git tag -d <tagname>
# リスト表示
git tag -l <pattern>
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?