Kinopyo Blog

プログラマとしてRuby, Rails, iPhone, iPad,Macなどなどと向き合う日々のログポース

Archive for the ‘Git’ Category

zshでgitの^caretは使えないっぽい: zsh: no matches found: HEAD^

2011年10月26日

前回の記事:gitの^記号はHEAD^を書いたのですが、zshでやるとこんなエラーに。。


zsh: no matches found: HEAD^

何かzshで^記号は特別の意味があるらしいです。

参考:http://stackoverflow.com/questions/6091827/git-show-head-doesnt-seem-to-be-working-is-this-normal

回避方法

2つあります。一つは同じ効果のHEAD~1を使う、もう一つはエスケープする方法です。

  • HEAD~1
  • HEAD/^

gitの^記号は

HEAD^

If you place a ^ at the end of a reference, Git resolves it to mean the parent of that commit.

HEAD^, which means “the parent of HEAD”:

http://progit.org/book/ch6-1.html#ancestry_references

通常ケースで言うとHEAD^は一個前のコミット、HEAD^^は2つ前のコミットってことですね。他の書き方はHEAD~2HEAD~5があります。

HEAD^1、HEAD^2

これは上記と若干違ってmergeのコミットに対してのみ有効です。マージの場合はparentが2つあるので、HEAD^1は今のブランチでのparent、HEAD^2は取得先のparentを差してます。

git reset –hardでミスった内容を取戻したいときはgit reflog

例えばgit reset –hard HEAD^で誤操作して内容を消してしまった、それを取戻したいときは

  • git reflogで取戻したいHEAD@{x}の番号を確認
  • git reset –hard HEAD@{1}で番号指定でもう一回git reset(ここでは例として1番にしてる)

reflogの定義は

a log of where your HEAD and branch references have been for the last few months.

いわば自分のローカルリポジトリのHEADが指していた情報を全部保存したログです。ブランチの切り替えやpull、コミットなどの情報がローカルで保存されるんです。

git log -g: git logのフォーマット(コミットログやコミット者の情報)で表示できます。

参考:

http://d.hatena.ne.jp/idesaku/20091106/1257507849

http://progit.org/book/ch6-1.html#reflog_shortnames

Git コンフリクトになった場合の対処

2011年10月12日

git pullとかgit mergeでコンフリクトとなったファイルを編集して、git add、git commitすればいいです。コミットメッセージも必要です。

git mergetoolでビジュアルのDiffソフトで差分を見れたり修正したりできます。

コミットログはこんな感じです。SVNとは違ってコミットログに残るのが何か慣れないです。


$ git log --oneline

63bc3d1 fixed merge conflict

bbfdd9e edit in master

3dcfb2f edit in work

9eedc58 made a