消したはずのブランチをチェックアウト
リモートリポジトリにpushしたけどローカルでマージしてないブランチを消すとこうなります。
( ・ω・)っ git branch -d unmerged warning: deleting branch 'unmerged' that has been merged to 'refs/remotes/origin/unmerged', but not yet merged to HEAD. Deleted branch unmerged (was b489e88).
なんか警告が出るけどきれいさっぱりブランチを消してくれますが、ここで最後の行に注目。なんかハッシュを表示してくれてますね。これをおもむろにブランチ代わりに打ち込むと…
( ・ω・)っ git checkout b489e88 Note: checking out 'b489e88'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is now at b489e88... ついにできた…やっと帰れる…!
>チェックアウトできる<
つまり、「git branch -d branch_name」は、ただ単に特定のコミットにつけられた「branch_name」という名前をとりあげるだけのコマンドだったということです。
ブランチの名前を消したところでコミットログはGitがちゃんと覚えているので、何の問題もなくチェックアウトできた、というわけです。.gitって隠しディレクトリを消したら何もかも忘れるけどね!こういう名無しブランチをチェックアウトすると親切にも「あのね、こうしたらまたなまえつけられるよ」と教えてくれています。
ということはブランチ名の代わりにハッシュを指定してマージできちゃう…?
( ・ω・)っ git merge 07g569d Updating 0398a398..07g569d Fast-forward README.md | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-)
>マージもできる<
ということは、やろうと思えば今の所ニーズが思い浮かばないけどあるブランチのコミットログを調べて、最新のコミットの2つくらい前のコミットをマージするなんてこともできる、と。