git : バージョン管理システム

MacPorts

2010-11-12

$ sudo port install git-core

db46 を入れようとしている。mercurial と同じように失敗しそうだ。。

macports の手順で db46 を入れたら成功した。

$ which git
/opt/local/bin/git

Macインストーラー

since 2011-07-21

Lion ではなく Snow Leopard で作業をする。

ダウンロード したのは、 git-1.7.6-x86_64-snow-leopard.dmg である。

ダブルクリックしてインストール。

"setup git PATH for ….sh" というファイルも(ターミナルから)実行しておいた。

ログオフして再度ログオンし直す。

$ which git
/usr/local/git/bin/git
$ git --version
git version 1.7.6

Ubuntu Linux

  • Ubuntu Linux : sudo apt-get instal git-core
    • gitk という GUI ツールが別途入手可能

Windows

ユーザの最初の設定

$ git config --global user.name "Your Name"
$ git config --global user.email you@example.com

好みでページャーの設定

[.bashrc]

export GIT_PAGER=lv

amend 機能

自分の名前やアドレスの設定をしないで commit してしまっても、直後に修正ができる。

$ git commit --amend --author='Takuya Nishimoto <nishimotz@gmail.com>'

cygwin / msysgit での運用

プロジェクトの作法

git init して最初の git add をする前に。。

$ echo "_*" >> .gitignore 
$ echo "*~" >> .gitignore 
$ echo "CVS" >> .gitignore 

_ではじまるファイル名を一時ファイルにする、というのは個人的な流儀。詳細は下記:

試行錯誤の記録

ファイル名の変更とファイルの移動

mv してから git add / git rm するより git mv したほうがよさそう。

$ git mv old_name new_name

ファイルの追加と削除

まとめて登録

$ git add -f .

管理したくないファイルを削除する

$ git rm --cached -r log/*

git checkout other-branch

  • current-branch を commit していない: merge される
  • current-branch が commit されている: other-branch そのものが出てくる

ssh で git clone

カレントディレクトリに git-test ディレクトリを作成し、そこに .git を作り、 master ブランチの checkout まで行う。

$ git clone ssh://remote-machine/home/username/git-test
Initialized empty Git repository in /home/username/git-test/.git/
The authenticity of host '***' can't be established.
RSA key fingerprint is *****.

Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '***' (RSA) to the list of known hosts.

username@remote-machine's password: (((pw)))
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 7 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (7/7), done.

$ ls git-test
hoge.c  hoge.h

git remote origin は git clone すれば設定済み??

$ git remote add origin ssh://xxxx/zzz
remote origin already exists.
$ git remote 
origin
$ git remote -h
Usage: git remote
       git remote add <name> <url>
       git remote rm <name>
       git remote show <name>
       git remote prune <name>
       git remote update [group]
$ git remote show
Usage: git remote show <remote>
$ git remote show origin
username@remote-machine's password: 
* remote origin
  URL: ssh://remote-machine/home/username/git-test
  Remote branch(es) merged with 'git pull' while on branch stable
    stable
  Tracked remote branches
    master stable

local-machine で修正を加えて git commit, git push する。

push された変更を remote-machine で checkout したい。

 $ git checkout
 M	rails/config/environment.rb
 M	rails/log/development.log
 反映されない

 $ git checkout -f
 やっと反映される

マージの解決

git commit しようとすると

fatal: cannot do a partial commit during a merge.

git merge しようとすると

xxxx.rb: needs merge

git add xxxx.rb すれば git commit できる。


実用Git
実用Git
posted with amazlet at 11.02.05
Jon Loeliger
オライリージャパン
売り上げランキング: 71675

git.txt · 最終更新: 2011/11/03 15:52 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0