553 文字
3 分
git memo

手元のgitメモが溜ってきたので放出!

Terminal window
% cat ~/.gitconfig
[user]
name = Yuki Matsukura
email = 秘密@秘密ドメイン
[color]
ui = auto
diff = auto
status = auto
branch = auto
interactive = auto

Subversion vs git#

subversionへの不満が爆発。

  • 2年前頃からtortoiseSVNでupdate,add,commitをしていると.svnディレクトリ内が壊れるようで、add,update,commitが一切できなくなる。回復するためには再チェックアウトするしかない。(過去2年で、かれこれ10回ぐらい起きた。)
  • ファイルが多くなるとcommit,updateがすごい遅い。(1,2分かかる)
  • チェックアウトすると小さいファイルを大量に作る→Disk IOが激しい

gitが良さそう。

  • 軽い
  • 大規模プロジェクトで利用されている

Web上の資料読んでもモデルが理解しづらいのでWeb+DB PRESS Vol.50を読むのが一番!

https://amzn.to/38PqRc9

Web+DBはあまり深く書いていないので、運用しているとかゆいところに手を出そうとしても手が出せない。もっとしっかり理解したい場合は、洋書だけどVersion Control with Gitがいい。

https://amzn.to/3hfQN5l

TIPS#

あるコミット分だけ反映#

Terminal window
% git fetch
% git-cherry-pick 0e736c1eff177f143ae55ab8971bae6e5753cdb6

ワークツリーの変更を取り消し#

Terminal window
% git checkout -- path/to/file

直前のコミット取り消し#

Terminal window
% git revert HEAD

mergeされていないbranchのリスト#

Terminal window
% git branch --no-merged

あとからbranchを作る#

Terminal window
% git branch new-branch
% git reset --hard

CVSやsvnのkeywordパラメータのように、Id:Id:を自動的に置換する設定#

Terminal window
% echo "* ident" >> .gitattributes

remote repositoryのbranchを消す#

空のブランチをremoteにpushすればいい。

Terminal window
% git push origin :20090918-sitemap

git fetchするだけでは、remoteの消えたbranchをローカルのtracking branchに反映してくれないので、
ローカルのtracking branchも消す

Terminal window
% git branch -d -r origin/20090907-sitemap

あとからブランチを作る#

小さな修正だと思って、masterをいじっていたら実は根が深く、branchを作っておけば良かったなぁと思ったときの対処法

Terminal window
% git commit -a
% git branch new-branch
% git reset --hard HEAD~1

worktreeをcommitしておく。現時点の作業がbranchになるため。
そして、index,worktreeを指定したrevisionに戻す。

UNIX設定ファイル共有#

ホームディレクトリのファイルをgitで管理すると共有が楽。

git memo
https://blog.teraren.com/posts/git-memo/
作者
Yuki Matsukura
公開日
2009-09-12
ライセンス
CC BY-NC-SA 4.0

コメント