<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DailyHckr &#187; git</title>
	<atom:link href="http://hylom.net/tag/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://hylom.net</link>
	<description>Hack, Hacker, Hackest</description>
	<lastBuildDate>Mon, 16 Jan 2012 13:32:56 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Gitでブランチを間違えて作業した上にpushまでしちゃった場合の対処方法</title>
		<link>http://hylom.net/2011/03/01/how-to-reset-remote-git-branch/</link>
		<comments>http://hylom.net/2011/03/01/how-to-reset-remote-git-branch/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 11:01:39 +0000</pubDate>
		<dc:creator>hylom</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://hylom.net/?p=1374</guid>
		<description><![CDATA[　時間ができたのでHandBrake 0.9.5の日本語化に着手しているのだが、うっかり0.9.4のブランチで作業してしまったあげく、SourceForge.JP上のリポジトリにpushしてしまい途方に暮れる。 　まあこういうミスをやる人は少ないだろうが、何かのヒントになるかもしれないので対処法をメモしておく。まず、「git log」コマンドで巻き戻したいcommitのハッシュを調べる。 $ git log 　： 　： commit 1485a5a2bbbb43eedbe131c919b7d604bcbd506d Author: unknown Date: Tue Jan 5 19:19:44 2010 +0900 update Installer, changelog, readme 　今回は、この「1485a5a2bbbb43eedbe131c919b7d604bcbd506d」というcommitまで巻き戻すことにする。作業中のブランチが操作したいものであることを確認したうえで、「git reset ＜対象のハッシュ＞」を実行する。 $ git branch -a jp-0.9.3 * jp-0.9.4 master original remotes/origin/HEAD -> origin/master remotes/origin/jp-0.9.3 remotes/origin/jp-0.9.4 remotes/origin/master remotes/origin/original $ git reset 1485a5 Unstaged changes after reset: M Jamrules M Makefile [...]]]></description>
			<content:encoded><![CDATA[<p>　時間ができたのでHandBrake 0.9.5の日本語化に着手しているのだが、うっかり0.9.4のブランチで作業してしまったあげく、SourceForge.JP上のリポジトリにpushしてしまい途方に暮れる。</p>
<p>　まあこういうミスをやる人は少ないだろうが、何かのヒントになるかもしれないので対処法をメモしておく。まず、「git log」コマンドで巻き戻したいcommitのハッシュを調べる。</p>
<pre>
$ git log
　：
　：
commit 1485a5a2bbbb43eedbe131c919b7d604bcbd506d
Author: unknown <hirom@.(none)>
Date:   Tue Jan 5 19:19:44 2010 +0900

    update Installer, changelog, readme
</pre>
<p>　今回は、この「1485a5a2bbbb43eedbe131c919b7d604bcbd506d」というcommitまで巻き戻すことにする。作業中のブランチが操作したいものであることを確認したうえで、「git reset ＜対象のハッシュ＞」を実行する。</p>
<pre>
$ git branch -a
  jp-0.9.3
* jp-0.9.4
  master
  original
  remotes/origin/HEAD -> origin/master
  remotes/origin/jp-0.9.3
  remotes/origin/jp-0.9.4
  remotes/origin/master
  remotes/origin/original

$ git reset 1485a5
Unstaged changes after reset:
M       Jamrules
M       Makefile
M       win/C#/Installer/Installer.nsi
M       win/C#/InstallerJp/doc/AUTHORS
M       win/C#/InstallerJp/doc/CREDITS
M       win/C#/InstallerJp/doc/NEWS
M       win/C#/Properties/AssemblyInfo.cs
M       win/C#/frmAbout.Designer.cs
</pre>
<p>　「git log」で巻戻ったことを確認する。</p>
<pre>
$ git log
commit 1485a5a2bbbb43eedbe131c919b7d604bcbd506d
Author: unknown <hirom@.(none)>
Date:   Tue Jan 5 19:19:44 2010 +0900

    update Installer, changelog, readme
</pre>
<p>　バージョン管理されているファイル自体は巻き戻されていないので、「-f」オプション付きでチェックアウトしてファイルも巻き戻す。</p>
<pre>
$ git checkout -f
</pre>
<p>　ここまでの作業でローカルブランチの巻き戻しは完了。続いてリモートブランチの巻き戻しを行う。ただし、当然ながらそのままpushすることはできない。</p>
<pre>
$ git push
Enter passphrase for key '/d/Users/hirom/.ssh/id_dsa':
To hylom@git.sourceforge.jp:/gitroot/handbrake-jp/handbrake-jp.git
 ! [rejected]        jp-0.9.4 -> jp-0.9.4 (non-fast-forward)
error: failed to push some refs to 'hylom@git.sourceforge.jp:/gitroot/handbrake-
jp/handbrake-jp.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
</pre>
<p>　そこで、いったんリモートブランチを削除した上で再度pushする。まずは削除。リモートブランチの削除は、「git push ＜リモートリポジトリ＞ :＜対象リモートブランチ＞」で行える。</p>
<pre>
$ git push origin :jp-0.9.4
Enter passphrase for key '/d/Users/hirom/.ssh/id_dsa':
To hylom@git.sourceforge.jp:/gitroot/handbrake-jp/handbrake-jp.git
 - [deleted]         jp-0.9.4
</pre>
<p>　あとは再度ローカルリポジトリをpushするだけ。</p>
<pre>
$ git push origin jp-0.9.4:jp-0.9.4
Enter passphrase for key '/d/Users/hirom/.ssh/id_dsa':
Counting objects: 233, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (146/146), done.
Writing objects: 100% (165/165), 30.48 KiB, done.
Total 165 (delta 119), reused 0 (delta 0)
To hylom@git.sourceforge.jp:/gitroot/handbrake-jp/handbrake-jp.git
 * [new branch]      jp-0.9.4 -> jp-0.9.4
</pre>
<p>　お粗末様でした。</p>
]]></content:encoded>
			<wfw:commentRss>http://hylom.net/2011/03/01/how-to-reset-remote-git-branch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gitメモ：ブランチを切ってないのにやばいコードを書いちゃった場合</title>
		<link>http://hylom.net/2010/07/30/git-branch-with-stash/</link>
		<comments>http://hylom.net/2010/07/30/git-branch-with-stash/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 00:32:22 +0000</pubDate>
		<dc:creator>hylom</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://hylom.net/?p=1302</guid>
		<description><![CDATA[　gitを使ってコードの管理をしている場合において、実験的なコードを書く場合はソースコードを編集する前にブランチを作成しておくのが基本だ。しかし、ついブランチを作成し忘れたままでコードを変更してしまった、というパターンがある。 　この場合、下記のようにgit stashでいったん変更点を保存した上で直前のcommitに戻し、新たなブランチを作成してそこでgit stash applyを行えばよい。 $ git stash $ git checkout hogehoge -b $ git stash apply $ git add hogehoge foobar $ git commit 　git stash、便利だ。]]></description>
			<content:encoded><![CDATA[<p>　gitを使ってコードの管理をしている場合において、実験的なコードを書く場合はソースコードを編集する前にブランチを作成しておくのが基本だ。しかし、ついブランチを作成し忘れたままでコードを変更してしまった、というパターンがある。</p>
<p>　この場合、下記のようにgit stashでいったん変更点を保存した上で直前のcommitに戻し、新たなブランチを作成してそこでgit stash applyを行えばよい。</p>
<pre>
$ git stash
$ git checkout hogehoge -b
$ git stash apply
$ git add hogehoge foobar
$ git commit
</pre>
<p>　git stash、便利だ。</p>
]]></content:encoded>
			<wfw:commentRss>http://hylom.net/2010/07/30/git-branch-with-stash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gitメモ：diffとやり直し</title>
		<link>http://hylom.net/2009/12/02/git_diff_rese/</link>
		<comments>http://hylom.net/2009/12/02/git_diff_rese/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 06:33:52 +0000</pubDate>
		<dc:creator>hylom</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://hylom.net/?p=1217</guid>
		<description><![CDATA[　最近久しぶりにgitを触って色々と忘れていたので再度メモ。]]></description>
			<content:encoded><![CDATA[<p>　最近久しぶりにgitを触って色々と忘れていたので再度メモ。</p>
<h4>mergeを取り消す</h4>
<p>　mergeを実行したらconflictが大量に出てしまったので取り消したい、という場合、下記を実行。</p>
<pre class="command">
$ git reset --hard ORIG_HEAD
</pre>
<h4>conflictを解決する</h4>
<p>　gitにはmergeを実行した場合にconflictを解決するコマンド「git mergetool」がある。conflictしているファイルに対して、順番にdiffツールを実行して編集を促すもの。しかし、Windows上のMSysGit環境で実行したら見事にvimのdiffが実行されたので個人的にはデフォルトでは使えない認定（自分はvimはあまり使えないので）。</p>
<pre class="command">
$ git mergetool
</pre>
<p>　.gitconfigの「merge」および「mergetool」項目で起動するツールを設定できるそうなので、今度はEmacsに設定してテストしてみようかな。</p>
<h4>diffを使う</h4>
<p>　<a href="http://www.kernel.org/pub/software/scm/git/docs/git-diff.html">マニュアル</a>に書いてあるけど、「git diff」コマンドの書式は下記のとおり。</p>
<pre>
git diff <比較元commit> <比較先commit> [<対象ファイルパス>]
</pre>
<p>　ここで、比較元・比較先commitはハッシュだけでなく、「HEAD」（最新のコミット）や「HEAD^」（最新の1つ前のコミット）、「HEAD^^」（最新の2つ前のコミット）、「HEAD~4」（最新の4つ前のコミット）などのほか、tagも利用可能。</p>
<p>　例えば最新のコミットと、その1つ前のコミットでdiffを取るには次のようにする。</p>
<pre class="command">
$ git diff HEAD^ HEAD hogehoge.py
</pre>
]]></content:encoded>
			<wfw:commentRss>http://hylom.net/2009/12/02/git_diff_rese/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TortoiseGitの記事を書きました</title>
		<link>http://hylom.net/2009/06/24/20090624_newarticle/</link>
		<comments>http://hylom.net/2009/06/24/20090624_newarticle/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 16:47:29 +0000</pubDate>
		<dc:creator>hylom</dc:creator>
				<category><![CDATA[My Works]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://hylom.net/2009/06/24/20090624_newarticle/</guid>
		<description><![CDATA[　SourceForge.JP Magazineで 実用レベルに達したWindows向けGitクライアント「TortoiseGit」でGitを始めよう を書きました。ふと TortoiseGitのWebページ を見たらバージョンが上がっていて、インストールしてみたらかなり使えるようになっていたので適当に日本語化したうえで記事を書くという、自作自演（笑）。 　 はてブコメント では「日本語のファイル名に対応していない現状で実用的か？」というものが見られたんですが、日本語ファイルの件はすっかり失念してました。もともとバージョン管理するようなファイル/ディレクトリには日本語のファイル名を使わないもので、一般的にもそうなのかとすっかり思いこんでいたのですが、世間は違うようです……。 　ただ、これはTortoiseGitだけの問題ではない話＆作者がこれを認識しているか不明なので、TortoiseGitがバージョン1.0になっても解決はされない可能性があります。ということで誰かがパッチを書いて送るべし。 # といっても、コマンドライン版（msysgit/cygwin）との互換性の話もあるので結局はGit本体のほうにファイル名の整合性をとるシステムが入るべきだという気もするのですが ## そして Cygwin 1.7ではコードページの切り替え機能によってUTF-8でファイル名を扱えるという話を初めて知った]]></description>
			<content:encoded><![CDATA[<p> 　SourceForge.JP Magazineで <a href="http://sourceforge.jp/magazine/09/06/19/0340248">  実用レベルに達したWindows向けGitクライアント「TortoiseGit」でGitを始めよう </a> を書きました。ふと <a href="http://code.google.com/p/tortoisegit/">  TortoiseGitのWebページ </a> を見たらバージョンが上がっていて、インストールしてみたらかなり使えるようになっていたので適当に日本語化したうえで記事を書くという、自作自演（笑）。</p>
<p> 　 <a href="http://b.hatena.ne.jp/entry/http://sourceforge.jp/magazine/09/06/19/0340248">  はてブコメント </a> では「日本語のファイル名に対応していない現状で実用的か？」というものが見られたんですが、日本語ファイルの件はすっかり失念してました。もともとバージョン管理するようなファイル/ディレクトリには日本語のファイル名を使わないもので、一般的にもそうなのかとすっかり思いこんでいたのですが、世間は違うようです……。</p>
<p> 　ただ、これはTortoiseGitだけの問題ではない話＆作者がこれを認識しているか不明なので、TortoiseGitがバージョン1.0になっても解決はされない可能性があります。ということで誰かがパッチを書いて送るべし。</p>
<p> # といっても、コマンドライン版（msysgit/cygwin）との互換性の話もあるので結局はGit本体のほうにファイル名の整合性をとるシステムが入るべきだという気もするのですが</p>
<p> ## そして <a href="http://www.okisoft.co.jp/esc/cygwin-21/index.html">  Cygwin 1.7ではコードページの切り替え機能によってUTF-8でファイル名を扱えるという話を初めて知った </a></p>
]]></content:encoded>
			<wfw:commentRss>http://hylom.net/2009/06/24/20090624_newarticle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gitで特定のファイルを無視させる</title>
		<link>http://hylom.net/2009/04/15/20090415_git_ignore/</link>
		<comments>http://hylom.net/2009/04/15/20090415_git_ignore/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 16:44:03 +0000</pubDate>
		<dc:creator>hylom</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://hylom.net/2009/04/15/20090415_git_ignore/</guid>
		<description><![CDATA[　gitで特定の拡張子などを持つファイルをtracking対象から外すには、.gitディレクトリがあるディレクトリに.gitignoreファイルで設定すればよい、というのはよく聞かれる話。たとえば自分の場合、下記のように設定することが多い。 *.pyc *~ *.bak 　で、毎回これを設定するのは面倒。そんなときは、適当なところにグローバル用の.gitignoreファイルを作成し、git configで そのファイルのパスを「core.excludesfile」に設定すればOK。 $ git config --global --add core.excludesfile "$HOME/.gitignore"]]></description>
			<content:encoded><![CDATA[<p> 　gitで特定の拡張子などを持つファイルをtracking対象から外すには、.gitディレクトリがあるディレクトリに.gitignoreファイルで設定すればよい、というのはよく聞かれる話。たとえば自分の場合、下記のように設定することが多い。</p>
<pre>
*.pyc
*~
*.bak
</pre>
<p> 　で、毎回これを設定するのは面倒。そんなときは、適当なところにグローバル用の.gitignoreファイルを作成し、git configで そのファイルのパスを「core.excludesfile」に設定すればOK。
<pre>
$ git config --global --add core.excludesfile "$HOME/.gitignore"
 </pre></p>
]]></content:encoded>
			<wfw:commentRss>http://hylom.net/2009/04/15/20090415_git_ignore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gitでローカルファイルのバックアップ</title>
		<link>http://hylom.net/2009/04/14/20090414_git/</link>
		<comments>http://hylom.net/2009/04/14/20090414_git/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 06:31:31 +0000</pubDate>
		<dc:creator>hylom</dc:creator>
				<category><![CDATA[Docs]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://hylom.net/2009/04/14/20090414_git/</guid>
		<description><![CDATA[　Gitでローカルファイルの差分バックアップをやってみるテスト。 前提： ミラーリングされているファイルサーバーがある いままでは作業用PCがクラッシュしても大丈夫なように、作業後にいちいちファイルをファイルサーバー中のディレクトリに上書きコピーしていた ファイル数が多くなる/容量が大きくなると面倒 これだと履歴管理ができない（Emacsの~.1のようなバックアップファイルに頼ることに） 　ということで、下記の手順でGitで差分バックアップをやってみる。 作業ディレクトリをgitリポジトリ化する。 $ git init $ git add ＜対象ファイル＞ $ git commit -m "＜コメント＞" ファイルサーバーにgitのbareリポジトリを作る $ cd ＜バックアップディレクトリ＞ $ mkdir ＜適当なディレクトリ名＞.git $ cd ＜ディレクトリ名＞.git $ git init --bare ファイルサーバー内のbareリポジトリにコミット $ cd ＜作業ディレクトリ＞ $ git remote add origin ＜ファイルサーバー上のbareリポジトリのパス＞ $ git push master:master 　あとは作業が一段落したタイミングごとにコミット＋pushをしていけばいいだけのはず。しかしこういう目的で使い出すとWindows上で動く、使いやすいGUIフロントエンドがほしくなるところではある。]]></description>
			<content:encoded><![CDATA[<p> 　Gitでローカルファイルの差分バックアップをやってみるテスト。</p>
<p> 前提：</p>
<ul>
<li>  ミラーリングされているファイルサーバーがある </li>
<li>  いままでは作業用PCがクラッシュしても大丈夫なように、作業後にいちいちファイルをファイルサーバー中のディレクトリに上書きコピーしていた </li>
<li>  ファイル数が多くなる/容量が大きくなると面倒 </li>
<li>  これだと履歴管理ができない（Emacsの~.1のようなバックアップファイルに頼ることに） </li>
</ul>
<p> 　ということで、下記の手順でGitで差分バックアップをやってみる。</p>
<ol>
<li>  作業ディレクトリをgitリポジトリ化する。
<pre>
$ git init
$ git add ＜対象ファイル＞
$ git commit -m "＜コメント＞"
  </pre>
</li>
<li>  ファイルサーバーにgitのbareリポジトリを作る
<pre>
$ cd ＜バックアップディレクトリ＞
$ mkdir ＜適当なディレクトリ名＞.git
$ cd ＜ディレクトリ名＞.git
$ git init --bare
  </pre>
</li>
<li>  ファイルサーバー内のbareリポジトリにコミット
<pre>
$ cd ＜作業ディレクトリ＞
$ git remote add origin ＜ファイルサーバー上のbareリポジトリのパス＞
$ git push master:master
  </pre>
</li>
</ol>
<p> 　あとは作業が一段落したタイミングごとにコミット＋pushをしていけばいいだけのはず。しかしこういう目的で使い出すとWindows上で動く、使いやすいGUIフロントエンドがほしくなるところではある。</p>
]]></content:encoded>
			<wfw:commentRss>http://hylom.net/2009/04/14/20090414_git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

