Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Saturday, February 23, 2013

Handling remote bare Git repository

When you have Git repositories as below.

  • CENTER.git : Central repository you can not manage
  • MAIN.git : Main repository that your team push into
  • LOCAL : Local repository on developers local machine

Merge on bare repository

You can't merge on bare repository such as MAIN.git because bare repository has no working copy. There are no ways to resolve the conflict when it occurs. Therefore, you must checkout the target branch into your local repository, merge your commits, then push to bare repository(MAIN.git).

Merge from external repository

Use 'git fetch' when there are some changes on CENTER.git. But this command doesn't update HEAD position. So you should use 'git reset --soft'.

# on MAIN.git
$ git fetch <CENTER.git>
$ git reset --soft HEAD
check commit histories using 'git log'.

Push specified branch

You can push local branch 'dev-local' into 'dev-remote' on origin.

$ git push origin dev-local:dev-remote

Clone from remote branch

You can checkout 'dev-remote' branch on MAIN.git into 'dev-local' branch on local machine:

git clone <MAIN.git>
git checkout -b dev-local remotes/origin/dev-remote

Push tags into remote repository

You can push local tags into remote repository.

$ git push --tags

This article is translated from Japanese.

Tuesday, September 04, 2012

Gitでタグ間の変更量を調べる

たとえばtag_1というタグを打っていて、このタグとHEADとの差分をappディレクトリ以下のみ調べるコマンドは以下。
$ git diff --shortstat tag_1 HEAD ./app
 79 files changed, 2657 insertions(+), 531 deletions(-)
--shortstatの代わりに--statを指定すると、変更したファイルごとの変更量も出力される。

Thursday, January 26, 2012

Gitのリモート(bare)リポジトリの扱い

Gitで、リモートにあるbareリポジトリ(repo.gitのようなリポジトリ)の扱いについてメモ。

ここでは以下のようなリポジトリ構成になっているものとします。

  • CENTER.git : チーム外で管理しているリポジトリ
  • MAIN.git : チームの開発者が普段pushするリポジトリ
  • LOCAL : 開発者が利用するリポジトリ

bareリポジトリでのマージ

bareリポジトリ(MAIN.git)上ではマージはできない。これは第一にbareリポジトリにはwork copyがないから。work copyがないと、マージで衝突したときに解決する手段がない。bareリポジトリ上のブランチのマージは、一度開発環境(LOCAL)など別のリポジトリ上にプル/チェックアウトし、そこでマージしたうえでリモートにpushする。

外部リポジトリからの取り込み

CENTER.gitで修正があり、それをMAIN.gitに取り込むにはgit fetchを使う。これだけで取り込みはOKのはずだが、fetchで取り込んだだけではHEADが更新された最新に移動しないので、reset --softする(work copyがないので、softでないとエラーとなる)。

# 以下、MAIN.git上での操作
$ git fetch <CENTER.git>
$ git reset --soft HEAD
この後でgit logすると、最新の変更がログに出力される。

ブランチを指定してpush

たとえばoriginに指定されているリモートリポジトリのdev-remoteブランチに、ローカルのdev-localブランチをpushする場合:

$ git push origin dev-local:dev-remote

リモートのブランチからクローンする

リモートリポジトリ(MAIN.git)のdev-remoteブランチを、ローカルにdev-localブランチとして取得する場合、まずgit cloneした後、リモートのブランチを指定してcheckoutする。

git clone <MAIN.git>
git checkout -b dev-local remotes/origin/dev-remote

リモートにタグを反映する

ローカルで作成したタグをリモートに反映する

$ git push --tags

Tuesday, April 12, 2011

gitで任意のファイルを、特定のリビジョンとGUIで比較(mac)

gitで任意のファイルを、特定のリビジョンとGUIで比較したい。Macの場合、GitXだとできないっぽい。 そこで、XCodeと一緒に入るFileMergeを使って差分をみる。
$ git difftool -t opendiff -y {revision} -- {path/to/file}