Git for Windows/msysgit で ユーザー名、パスワードの入力頻度を下げる
複数のリポジトリを clone する必要があり、一発 clone するスクリプト書いた。
社内の認証がhttpによる認証のため、毎回user/passwordを入力するのがだるい。
そこで、 http://$user:$password@example.co.jp/git/reponame
みたいな感じで、URL に埋め込んだら動いた。
しかし、git remote -v で URLに平文で丸見え。だめである。
調べたら、cache する仕組みがあるようだ。
環境
- Windows 8.1 Update
- Git for windows (1.9.2)
- msysgit (1.9.0)
結論
まず、結論を。
wincred を用いる。wincred は Git に同梱されている。
$ git config --global credential.helper wincred
いくつかの方法を試したので記録として残しておきます。
credential cache を用いる(Linux)
$ git config --global credential.helper cache
しかし msysgit 上ではエラーになってしまった。
git: 'credential-cache' is not a git command. See 'git --help'.
$ git fetch origin master
git: 'credential-cache' is not a git command. See 'git --help'.
..
git-credential-winstore を使う (Git for Windowsの場合)
ぐぐると、stackoverflowに。
http://stackoverflow.com/questions/11693074/git-credential-cache-is-not-a-git-command
○手順
- ダウンロードする
http://gitcredentialstore.codeplex.com/
ここから git-credential-winstore.exe をダウンロードする。現在の安定版は 1.2 。
- 実行する
- 設定する
$ git config --global credential.helper winstore
下記のようなダイアログが出現しユーザー名とパスワードが一時的に保存されます。
実行
社内
$ time git fetch origin master
..
real 0m21.099s
user 0m0.000s
sys 0m0.015s
社外 (bitbucket)
$ time git fetch bb master
..
real 0m43.869s
user 0m0.015s
sys 0m0.015s
めっちゃ遅い。。
1.4 Beta
$ time git fetch bb master
..
real 1m23.322s
user 0m0.015s
sys 0m0.062s
$ time git fetch origin master
..
real 1m0.874s
user 0m0.000s
sys 0m0.015s
もっと遅い。
git-credential-wincred
git-credential-wincred.exe を試してみる。
こちらは、Git同梱。
$ git config --global credential.helper wincred
社内
$ time git fetch origin master
..
real 0m0.403s
user 0m0.015s
sys 0m0.000s
社外
$ time git fetch bb master
..
real 0m7.669s
user 0m0.015s
sys 0m0.000s
これでいこう。
分散バージョン管理の機能比較まとめ
DVCSで有名なものですと、 Git , Mercurial, Bazaar があります。
最近では、Veracity という分散バージョン管理も出てきました。どのように違ってどういう基準で選ぶと良いか悩みますね。これらの違いはなんでしょうか?
そこで、比較資料をまとめてみました。
公式サイト一覧
Git | http://git-scm.com/ |
Mercurial | http://mercurial.selenic.com/ |
Bazaar | http://bazaar.canonical.com/ |
Veracity | http://veracity-scm.com/ |
DVCS 比較資料
新しい(と思われる)順番に並べました。
- DVCS 選択: Git それとも Mercurial? | Atlassian
- Veracity,Git,Mercurial,Bazaar,Fossilの比較
- PEP 374 -- Choosing a distributed VCS for the Python project
- これから分散バージョン管理システムを始める人へ - Google スライド
- ユカイ、ツーカイ、カイハツ環境!(3):分散バージョン管理Git/Mercurial/Bazaar徹底比較 (1/5) - @IT
- - DVCSAnalysis - support - Analysis of Git and Mercurial - User support for Google Project Hosting - Google Project Hosting
- 分散型バージョン管理システムはどれが良い? | スラッシュドット・ジャパン デベロッパー
バージョン管理ソフトウェアの比較資料
従来の集中型を含めたバージョン管理ソフトウェアの比較資料
- http://en.wikipedia.org/wiki/Comparison_of_revision_control_software
- も英語ですが、DVCSだけではなく、バージョン管理ソフトウェア機能やコマンドの比較が充実しています。比較対象が非常に多いですね。
- 分散バージョン管理で間違いないって、ベイビー - The Joel on Software Translation Project
- 分散バージョン管理入門 (イラスト入り) - tcha.org
- 作者: 岡本隆史,武田健太郎,相良幸範
- 出版社/メーカー: 技術評論社
- 発売日: 2012/07/10
- メディア: 単行本(ソフトカバー)
- 購入: 7人 クリック: 103回
- この商品を含むブログ (25件) を見る
- 作者: 藤原克則
- 出版社/メーカー: 秀和システム
- 発売日: 2013/02
- メディア: 単行本
- 購入: 3人 クリック: 13回
- この商品を含むブログ (15件) を見る
Visual Studio にて設定すべき .gitignore / .hgignore
.gitignore や .hgignore で管理対象から無視することができるのはご存知ですよね。
Visual Studio にて無視するファイル一覧をMSDNで探したけど無かったので stackoverflow で調べたらあったのでメモ。あと、教えてもらった方法も追記。
- stackoverflow の回答例
- github / .gitignore を用いる方法
無視ファイルの設定
.gitignore の場合
gitの場合は、 .gitignore をおいておきます。
.hgignore
.hgignore *1 に下記内容を記載してください。Mercurialの場合の無視ファイルは、デフォルトは正規表現で記述するので、glob文法(SHELL形式のパターンマッチングとかのやつ)にするため一行目 *2に syntax:glob と 記載します。
syntax:glob *.obj *.exe *.exp *.pdb *.dll *.user *.aps *.pch *.vspscc *_i.c *_p.c *.ncb *.suo *.tlb *.tlh *.bak *.cache *.ilk *.log *.zip [Dd]ebug*/ *.lib *.sbr Thumbs.db [Ll]ib/ [Rr]elease*/ [Tt]est[Rr]esults/ _UpgradeReport_Files/ _ReSharper.*/
感想
sln (ソリューションファイル) は 無視ファイルにはしないんですね。1プロジェクトだと無視したりしています。stackoverflowの回答例に追加して bin obj フォルダが指定が合ったほうがよさそう。
いただいたコメント
Twitter上でリプライ頂きました。とても参考になります。ありがとうございます。
@gab_km @cointoss1973 github に gitignore というプロジェクトがあるのでそこにあるのを使えばOK
— いじゅういん (@kei10in) 2012年9月11日
@cointoss1973 binとobjもあるといいと思います。
— いわた (@wonderful_panda) 2012年9月12日
@cointoss1973 それってDebugで始まるディレクトリとか無視されますけど、Debug*/にする必要ってあるんでしたっけ? x64とかだとsuffixつくのかな?私はVisual HG使わないときは面倒でも bin/Debug/とobj/Debug/とかやってます。
— TAKAHIRO (@c_o_t) 2012年9月12日
@cointoss1973 あとMSTest使ってるときは.vsmdiも除外してますね。これはプロジェクトによりけりでしょうが…。私はそれでソリューションとvsmdiの無駄なコンフリクトをなくしてます。
— TAKAHIRO (@c_o_t) 2012年9月12日
元ネタ
Git と Mercurial が Subversion より優れている点
リポジトリの初期化
hg init
- Subversion
svnadmin create /path/to/repo svn import http://long.url.to/repo yourwork rm -R yourwork svn checkout http://long.url.to/repo yourwork
そうなんです。もちろん Subversion でも一人で始めることができます。しかし「うぁー、めんどくせー!!」ってことなんです。
ひとりでも"簡単"に始められるDVCSをオススメします。
proxy 経由で 社内から github にアクセスする方法
簡単そうでなかなかできませんでしたが、ssh経由 github にアクセスできましたのでその作業手順をご紹介します。
環境
- Windows XP
- cygwin http://www.cygwin.com/ git や ssh など必要なパッケージはcygwinインストール時に選択していること
- github のアカウント https://github.com/
つかったもの
connect.c の準備
まず connect.c をダウンロードして適当なディレクトリにおきます。下記は tools を作成してその下におきました。
ソースコードのコメントに記載してあるように、コンパイルします。
tkondou@hostname ~/tools $ gcc connect.c -o connect $ ls connect.c connect.exe
connect.exe ができました。
SSH Public キーの作成
$ ssh-keygen -t rsa -C "foo@bar.com"
にて ~/.ssh/id_rsa と id_rsa.pub ができます。
id_rsa..pub の内容を github の Account Settings の SSH Public Keys に登録してください。
~/.ssh/config を準備
$ cat ~/.ssh/config ProxyCommand C:/cygwin/home/tkondou/tools/connect.exe -H proxy.mycompany.co.jp:80 %h %p Host github.com User git Port 22 Hostname github.com IdentityFile "C:\cygwin\home\tkondou\\.ssh\id_rsa" TCPKeepAlive yes IdentitiesOnly yes Host ssh.github.com User git Port 443 Hostname ssh.github.com IdentityFile "C:\cygwin\home\tkondou\\.ssh\id_rsa" TCPKeepAlive yes IdentitiesOnly yes
connect.exeを指定するパスは / で指定する必要がありますので注意してください。
proxy.mycompany.co.jp:80 の部分は、各自のプロキシ環境に合わせてください。
tkondouはcygwinのユーザ名ですのでこちらも適切に変更してください。
ssh での接続確認
$ ssh -F ~/.ssh/config ssh.github.com The authenticity of host '[ssh.github.com]:443 (<no hostip for proxy command>)' can't be established. RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[ssh.github.com]:443' (RSA) to the list of known hosts. PTY allocation request failed on channel 0
PTY allocation request failed on channel 0というエラーでOKです。
これは git のコマンドがないためです。
git clone にて github のリポジトリのコピーをつくる
cointoss1973 の github アカウントから stream を git 経由で落としてきます。
tkondou@hostname ~/workspace $ git clone ssh://git@ssh.github.com:443/cointoss1973/stream.git Cloning into stream... remote: Counting objects: 7, done. remote: Compressing objects: 100% (7/7), done. Receiving objects: 100% (7/7), 4.60 KiB, done. remote: Total 7 (delta 0), reused 7 (delta 0)
ssh のホスト名を間違っていたみたいでしばらくハマりましたが、無事にアクセスすることができました。
- 作者: 濱野純(Junio C Hamano)
- 出版社/メーカー: 秀和システム
- 発売日: 2009/09/19
- メディア: 単行本
- 購入: 31人 クリック: 736回
- この商品を含むブログ (155件) を見る