3
3

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 5 years have passed since last update.

Git コマンド忘れたら見るメモ

3
Last updated at Posted at 2014-12-21

共用の中央リポジトリ作成

git init --bare --shared <repo>

  • --bare: 中央リポジトリ作成時に付けるオプション
  • --shared: 共用リポジトリにつけるオプション.つけると .git/ 以下の権限がdrwxrwsr-xになり,グループメンバーがプッシュ可能に.

エイリアス

git config alias.<name> <command>

毎回git statusとか打ってられない時に.

git alias.st status

私のtree

git alias.tree 'log --color --graph --all --format="%x09%C(blue bold)%an%Creset%x09%C(yellow)%h%Creset %C(magenta reverse)%d%Creset %s"'

私のtreeof

git alias.treeof 'log --color --graph --format="%x09%C(blue bold)%an%Creset%x09%C(yellow)%h%Creset %C(magenta reverse)%d%Creset %s"'
  • develop ブランチの生長を見たければ,git treeof develop みたいに使える.

ファイルいじって,やっぱやめる時

src/ 以下のファイルをいじった.けどやっぱ前の状態に戻りたい時

rm -rf src
git checkout src

最後のコミット時の src/ の状態を持ってこられる.

今のコミット,間違えた! って時

これらの作業は過去のコミットに対する変更!
変更が複数人に影響するときは使うべきではない?

ステージングエリアに乗せ忘れた

  1. git add <file> でステージングエリアに乗せて
  2. git commit --amend でコミットを修正.(-mオプションも可)

いらないファイルまでコミットした

  1. git reset --soft HEAD^ で一つ前のコミットを取り消し.
    • この際,ステージングエリアの状態は コミット前のもの+その後にステージングされたもの が含まれる.(詳しくは下記外部リンク参照)
  2. git reset <file> でいらないファイルをアンステージ.
  3. git commit でコミット!

murankの日記 様の記事によると,実際はHEADの移動(+ ステージングエリアの状態変更(+ ワーキングディレクトリの状態変更))のようで,取り消したコミットには戻れるようだ.内部の構造は要勉強か.)


今後も追記予定.

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?