Action disabled: revisions

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

<html> <div class="amazlet-box" style="margin-bottom:0px;"><div class="amazlet-image" style="float:left;margin:0px 12px 1px 0px;"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4274068641/r4wh-22/ref=nosim/" name="amazletlink" target="_blank"><img src="http://ecx.images-amazon.com/images/I/51WQ7GsnOZL._SL160_.jpg" alt="Gitによるバージョン管理" style="border: none;" /></a></div><div class="amazlet-info" style="line-height:120%; margin-bottom: 10px"><div class="amazlet-name" style="margin-bottom:10px;line-height:120%"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4274068641/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">Gitによるバージョン管理</a><div class="amazlet-powered-date" style="font-size:80%;margin-top:5px;line-height:120%">posted with <a href="http://www.amazlet.com/browse/ASIN/4274068641/r4wh-22/ref=nosim/" title="Gitによるバージョン管理" target="_blank">amazlet</a> at 12.02.20</div></div><div class="amazlet-detail">岩松 信洋 上川 純一 まえだこうへい 小川 伸一郎 <br />オーム社 <br />売り上げランキング: 46372<br /></div><div class="amazlet-sub-info" style="float: left;"><div class="amazlet-link" style="margin-top: 5px"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4274068641/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">Amazon.co.jp で詳細を見る</a></div></div></div><div class="amazlet-footer" style="clear: left"></div></div> </html>

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

2013-03-14 Xcode 4.6 でコマンドラインツールを入れると git が入っている。

$ which git
/usr/bin/git
$ git --version
git version 1.7.12.4 (Apple Git-37)

Ubuntu Linux

  • Ubuntu Linux : sudo apt-get instal git-core
    • gitk という GUI ツールが別途入手可能
$ cp /etc/bash_completion.d/git-prompt ~/.git-prompt.sh

$ nano ~/.bashrc

# ファイルの最後に以下を追加
source ~/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
PS1='[\u@\h \W]$(__git_ps1 "[\[\033[32m\]%s\[\033[0m\]]")\$ '

Windows

  • cygwin で簡単に入れられる。

コマンドプロンプトで pager の指定

lv for Windows だと UTF-8 ファイルを表示できるので lv に path を通しておく。

set GIT_PAGER=lv -Iu

または

git config --global core.pager "lv -Iu"

less のままで長い行が切れないようにする:

git config --global core.pager "less -r"

改行コード制御

autocrlf: Windows では素直に true にしとくべきという話。。

抑制するなら git config core.autocrlf false

  • msysgit には unix2dos と dos2unix のコマンドも入っている

ファイルモード

ユーザの最初の設定

$ 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>'

push.default

warning: push.default is unset を調べたら:

git version 1.8.0 から引数なしの push が出来なくなった|mattintosh note http://bit.ly/VNWanV

git config --global push.default simple

プロジェクトの作法

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 clone

リモートリポジトリの 2.4 ブランチだけを clone する:

git clone -b 2.4 --single-branch git@github.com:user/repo.git

<html><hr /> <div class="amazlet-box" style="margin-bottom:0px;"><div class="amazlet-image" style="float:left;margin:0px 12px 1px 0px;"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4873114403/r4wh-22/ref=nosim/" name="amazletlink" target="_blank"><img src="http://ecx.images-amazon.com/images/I/51B2dc%2BsJGL._SL160_.jpg" alt="実用Git" style="border: none;" /></a></div><div class="amazlet-info" style="line-height:120%; margin-bottom: 10px"><div class="amazlet-name" style="margin-bottom:10px;line-height:120%"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4873114403/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">実用Git</a><div class="amazlet-powered-date" style="font-size:80%;margin-top:5px;line-height:120%">posted with <a href="http://www.amazlet.com/browse/ASIN/4873114403/r4wh-22/ref=nosim/" title="実用Git" target="_blank">amazlet</a> at 11.02.05</div></div><div class="amazlet-detail">Jon Loeliger <br />オライリージャパン <br />売り上げランキング: 71675<br /></div><div class="amazlet-sub-info" style="float: left;"><div class="amazlet-link" style="margin-top: 5px"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4873114403/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">Amazon.co.jp で詳細を見る</a></div></div></div><div class="amazlet-footer" style="clear: left"></div></div> </html>

git.txt · 最終更新: 2021/06/06 17:29 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