• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

間違ってremoteブランチを作ってしまったのですが、勉強になったので記事にしておきます ;P

###remoteにlocal_deployブランチを作成

shell>>
$ git push origin local_deploy #間違って作成
$ git branch -a

  • master
    origin/HEAD
    origin/deploy
    origin/local_deploy #ローカルにも反映されている
    origin/master
    <<--

###remoteブランチを削除
shell>>
$ git push origin :local_deploy
<<--
これでサーバ側は反映されました。

###別のローカルリポジトリ(cloned)で削除が反映されない
しかしもう一つ別のディレクトリで同じgitリポジトリをcloneしていて、そちらで削除が反映されない状況に。

下記の1.の説明にあるように、(remoteブランチの追加は自動でされるが)削除されたものはローカルで明示的に削除しないといけないようです。

Delete unneeded branch
$ git clone git://git.kernel.org/.../git.git my.git
$ cd my.git
$ git branch -d -r origin/todo origin/html origin/man (1)
$ git branch -D test (2)

  1. Delete remote-tracking branches "todo", "html", "man". Next fetch or pull will create them again unless you configure them not to. See git-fetch(1).  
  2. Delete "test" branch even if the "master" branch (or whichever branch is currently checked out) does not have all commits from test branch. 

http://www.kernel.org/pub/software/scm/git/docs/git-branch.html

(上によると、git branch -d -r origin/removed_branchでもremoteブランチが削除できるようですね)

###コマンドgit remote show origin, git remote prune origin
git remote辺りにコマンドがあると知ったので見てみると、git remote showがありました。
確認すると、腐りかけた(Stale)tracking branchと表示されています。

shell>>
$ git remote show origin

  • remote origin
    URL: ssh://git.s21g.com/mnt/git/blog.git
    Remote branch merged with 'git pull' while on branch master
    master
    Stale tracking branch (use 'git remote prune')
    local_deploy
    Tracked remote branches
    deploy master
    <<--

そして、pruneで削除。ヘルプには、--dry-runでやるとどのブランチをpruneするかレポートしてくれて、実際のactionはしない旨が記述されているのですが、私の環境では削除されてしまいました。

shell>>
$ git remote prune origin --dry-run
<<--

###Refs
http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
http://www.kernel.org/pub/software/scm/git/docs/git-branch.html
http://reinh.com/blog/2008/04/18/git-push-just-the-tip.html

posted by satoko satoko on Fri 31 Oct 2008 at 12:54 with 0 comments

Gitに関するリンク集
http://blog.s21g.com/articles/548

gitをやり始めて時間が経ちますが、まだまだ知らないことばかり。
もう一度リンク集作ってみました。

###複数で開発するとき
git-pushのコツ:remoteブランチとか
http://reinh.com/blog/2008/04/18/git-push-just-the-tip.html

ブランチを使った開発の流れ
http://b.lesseverything.com/2008/3/25/got-git-howto-git-and-github

###gitリポジトリからのdeploy
CapistranoでGitを使う方法のメモ
http://blog.s21g.com/articles/807

rakeタスクからdeployする手順/ワークフロー
http://www.brynary.com/2008/8/3/our-git-deployment-workflow

###初心者にも役立つもの
Git It, Got It? Good!:pdf。これシンプルで分かりやすいと思います
http://assets.reinh.com/talks/GIT.pdf
http://reinh.com/blog/2008/02/19/git-it-got-it-good.html

Git用語Glossary
http://www.kernel.org/pub/software/scm/git/docs/user-manual.html#glossary

毎日使うgitコマンド:gitコマンドサンプルが多いのが良
http://www.kernel.org/pub/software/scm/git/docs/everyday.html

posted by satoko satoko on Thu 30 Oct 2008 at 17:05 with 0 comments

via http://ozmm.org/posts/git_post_commit_for_profit.html

gitのrefspecがよくわからなくて、調べていたら出会った記事です。

###.git/hooks/pre-commitをshellスクリプトで
shell>>
$ chmod 744 .git/hooks/pre-commit
$ cat .git/hooks/pre-commit
#!/bin/sh
rake test
<<--

こういうのもありました。
http://reinh.com/blog/2008/02/21/git-pre-commit-hook.html

shell>>
#!/bin/sh
rake spec 2> /dev/null
<<--

###.git/hooks/pre-commitをrubyで
shell>>
$ cat .git/hooks/pre-commit
#!/usr/bin/env ruby
if whoami.strip != 'deploy'
puts "You need to be deploy!"
exit 1
else
exit 0
end
<<--

###その他のhooks
.git/hooksには下記のようなファイルがあるので、preもpostもできるようです。
shell>>
post-commit
post-receive
post-update
pre-applypatch
pre-commit
pre-rebase
<<--

###pre-push hookはないのか
と思ったら、こういうパッチを書いている方がいます。パッチほとんどやったことないので、今度やってみよう。

http://kerneltrap.org/mailarchive/git/2008/8/19/2996404

posted by satoko satoko on Thu 30 Oct 2008 at 16:35 with 0 comments