<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="https://tm.root-n.com/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel>
        <title>Tipsというかメモ unix:command:git:operation</title>
        <description></description>
        <link>https://tm.root-n.com/</link>
        <lastBuildDate>Wed, 19 Nov 2025 02:07:23 +0900</lastBuildDate>
        <generator>FeedCreator 1.7.2-ppt DokuWiki</generator>
        <image>
            <url>https://tm.root-n.com/lib/images/favicon.ico</url>
            <title>Tipsというかメモ</title>
            <link>https://tm.root-n.com/</link>
        </image>
        <item>
            <title>git :: git commit のやり直し</title>
            <link>https://tm.root-n.com/unix:command:git:operation:amend_commit</link>
            <description>commit した直後に、「しまった、まだ修正すべき箇所があった。これから修正する箇所も、さっきの commit に含めたい」というような状況になった場合の対処です。

下記のように commit に --amend オプションでやり直しができます。</description>
        <category>unix:command:git:operation</category>
            <pubDate>Mon, 13 May 2013 18:58:01 +0900</pubDate>
        </item>
        <item>
            <title>git :: マシンAで作成したブランチを、マシンBでチェックアウトする</title>
            <link>https://tm.root-n.com/unix:command:git:operation:checkout_branch</link>
            <description>下記は、マシンAで作成した「rev001」ブランチを、マシンBでチェックアウトする例です。

マシンA での操作

	*  ブランチの確認


$ git branch
* master


	*  rev001 ブランチの作成


$ git branch rev001</description>
        <category>unix:command:git:operation</category>
            <pubDate>Fri, 05 Oct 2012 14:06:21 +0900</pubDate>
        </item>
        <item>
            <title>git :: ブランチを指定して clone する</title>
            <link>https://tm.root-n.com/unix:command:git:operation:clone_b</link>
            <description>ブランチを指定して clone する



% git clone -b &lt;branch_name&gt; &lt;user_name&gt;@&lt;host&gt;:&lt;repository_name&gt; .


	*  -b : ブランチの指定</description>
        <category>unix:command:git:operation</category>
            <pubDate>Wed, 05 Feb 2014 20:41:21 +0900</pubDate>
        </item>
        <item>
            <title>git :: ブランチ間の diff を見る</title>
            <link>https://tm.root-n.com/unix:command:git:operation:diff_between_branch</link>
            <description>ブランチ間の diff を見る



% git diff &lt;branch1&gt;..&lt;branch2&gt;


ファイル名だけ表示



% git diff --name-only &lt;branch1&gt;..&lt;branch2&gt;


	*  --name-only : ファイル名オンリー</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 06 Feb 2014 14:48:44 +0900</pubDate>
        </item>
        <item>
            <title>git :: リビジョン間の diff をとる</title>
            <link>https://tm.root-n.com/unix:command:git:operation:diff_between_revision</link>
            <description>$ git diff &lt;比較元のハッシュ値&gt; &lt;比較先のハッシュ値&gt; /path/to/file</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 20 Sep 2012 15:36:20 +0900</pubDate>
        </item>
        <item>
            <title>git :: リモートリポジトリとワーキングツリー(作業ツリー)の差分を見る</title>
            <link>https://tm.root-n.com/unix:command:git:operation:diff_from_remote_to_working</link>
            <description>1. まず、git pull せずに、git fetch する

$ git fetch
	*  fetch することで、まず最初にローカルリポジトリにマージされる。
		* ワーキングツリーへのマージはまだ行われない。






2. リモートリポジトリとワーキングツリーの差分を見る</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 20 Sep 2012 15:34:40 +0900</pubDate>
        </item>
        <item>
            <title>git :: 特定ファイルの変更履歴(diff)を見る</title>
            <link>https://tm.root-n.com/unix:command:git:operation:log_p</link>
            <description>特定ファイルの変更履歴(diff)を見る



$ git log -p path/to/file</description>
        <category>unix:command:git:operation</category>
            <pubDate>Wed, 29 Jan 2014 14:44:35 +0900</pubDate>
        </item>
        <item>
            <title>git :: 特定のコミットのみ取り込みたい(cherry-pick)</title>
            <link>https://tm.root-n.com/unix:command:git:operation:merge_specific_commit</link>
            <description>リモートリポジトリの特定のコミット(ハッシュ値のcommit-id)だけを、ワーキングツリー(作業ツリー)に取り込みたい場合の操作。


	*  まず全てのコミットをローカルリポジトリに取り込む(まだワーキングツリーには取り込まない)</description>
        <category>unix:command:git:operation</category>
            <pubDate>Sat, 01 Dec 2012 14:35:18 +0900</pubDate>
        </item>
        <item>
            <title>git :: 手元(working directory)の変更を commit せずに、pull したい時</title>
            <link>https://tm.root-n.com/unix:command:git:operation:no_commit_and_pull</link>
            <description>手元(working directory)の変更を commit せずに pull しようとすると下記のエラーで怒られます。



error: Your local changes to the following files would be overwritten by merge:
        path/to/file
Please, commit your changes or stash them before you can merge.
Aborting</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 20 Sep 2012 15:35:31 +0900</pubDate>
        </item>
        <item>
            <title>git :: 「No newline at end of file」の対処</title>
            <link>https://tm.root-n.com/unix:command:git:operation:no_newline_at_end_of_file</link>
            <description>ファイルを何も修正していない状態で保存した時、git status で変更とみなされる時があります。

git dff してみると下記のように「\ No newline at end of file」と表示されます。


% git diff

 :

\ No newline at end of file

 :</description>
        <category>unix:command:git:operation</category>
            <pubDate>Sat, 09 Nov 2013 14:16:54 +0900</pubDate>
        </item>
        <item>
            <title>リモートへのブランチの push ／ ローカルへのブランチ checkout</title>
            <link>https://tm.root-n.com/unix:command:git:operation:push_branch2remote_checkout_branch2local</link>
            <description>リモートへのブランチの push

	*  サーバー１


% git push origin &lt;branch_name&gt;


ローカルへのブランチ checkout

	*  サーバー２


% git fetch
% git checkout -b &lt;branch_name&gt; origin/&lt;branch_name&gt;






	*  リモートブランチの削除</description>
        <category>unix:command:git:operation</category>
            <pubDate>Mon, 03 Mar 2014 15:36:14 +0900</pubDate>
        </item>
        <item>
            <title>git :: リモートリポジトリを再構築する</title>
            <link>https://tm.root-n.com/unix:command:git:operation:rebuild_remote_repository</link>
            <description>　今回は、すでに存在する staging ブランチを削除して、master ブランチから新たに staging ブランチを再構築します。


	*  現在の状態


$ git br -a
  master
* staging
  remotes/origin/HEAD -&gt; origin/master
  remotes/origin/master
  remotes/origin/staging</description>
        <category>unix:command:git:operation</category>
            <pubDate>Tue, 17 Jul 2018 12:29:52 +0900</pubDate>
        </item>
        <item>
            <title>git :: git commit の取り消し</title>
            <link>https://tm.root-n.com/unix:command:git:operation:reset</link>
            <description>ワークディレクトリ(作業ツリー)の内容はそのまま、つまり変更内容はそのままでコミットだけを取り消したい場合



% git reset --soft HEAD^


	*  --soft : 変更内容はそのまま
	*  HEAD^ : ひとつ前のコミットの意味</description>
        <category>unix:command:git:operation</category>
            <pubDate>Wed, 05 Feb 2014 19:53:12 +0900</pubDate>
        </item>
        <item>
            <title>git :: git add の取り消し</title>
            <link>https://tm.root-n.com/unix:command:git:operation:reset_add</link>
            <description>$ git reset HEAD &lt;FILE or DIR&gt;</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 20 Sep 2012 15:34:05 +0900</pubDate>
        </item>
        <item>
            <title>git :: git pull の取り消し</title>
            <link>https://tm.root-n.com/unix:command:git:operation:reset_pull</link>
            <description>$  git reset --hard HEAD^
	*  --hard : ワークディレクトリの物理的変更を行う(ワークディレクトリの内容も書き換える)
	*  HEAD^ : 1つ前の状態</description>
        <category>unix:command:git:operation</category>
            <pubDate>Fri, 05 Oct 2012 15:20:59 +0900</pubDate>
        </item>
        <item>
            <title>git :: git push の取り消し</title>
            <link>https://tm.root-n.com/unix:command:git:operation:reset_push</link>
            <description>*  git push の取り消し


% git push -f origin HEAD^:&lt;branch_name&gt;</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 13 Feb 2014 15:08:39 +0900</pubDate>
        </item>
        <item>
            <title>git :: git rm で削除したファイルを復活させる</title>
            <link>https://tm.root-n.com/unix:command:git:operation:reset_rm_recover</link>
            <description>最新のコミットから「hoge.txt」を復活させる場合



git reset HEAD hoge.txt
git checkout hoge.txt


過去のコミットから復活させる場合は下記のように変更する


	*  ブランチを切ってない場合
		*  一世代前：git reset HEAD~ hoge.txt
		*  二世代前：git reset HEAD~~ hoge.txt</description>
        <category>unix:command:git:operation</category>
            <pubDate>Tue, 05 Mar 2013 16:12:20 +0900</pubDate>
        </item>
        <item>
            <title>git :: 誤って削除したファイルを元に戻す</title>
            <link>https://tm.root-n.com/unix:command:git:operation:restore_removed_file</link>
            <description>誤って削除してしまったファイルを元に戻します。


$ git checkout HEAD -- 誤って削除したファイル名</description>
        <category>unix:command:git:operation</category>
            <pubDate>Sat, 01 Dec 2012 14:37:32 +0900</pubDate>
        </item>
        <item>
            <title>git :: ハッシュ値を元に、特定ファイルをその時の状態に戻す</title>
            <link>https://tm.root-n.com/unix:command:git:operation:revert_in_commitid</link>
            <description>$ git log /path/to/file # 戻したい状態のハッシュ値を調べる
$ git checkout &lt;ハッシュ値&gt; /path/to/file # checkout でその時の状態に戻す

上記を最新の状態に戻す
$ git checkout HEAD /path/to/file # checkout HEAD で最新の状態に戻す

checkout しっぱなしのファイルがないか調べる

.git のあるディレクトリで下記コマンドを実行</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 20 Sep 2012 15:35:07 +0900</pubDate>
        </item>
        <item>
            <title>git :: git 管理下から外す</title>
            <link>https://tm.root-n.com/unix:command:git:operation:rm_cached</link>
            <description>単体のファイル



% git rm --cached /path/to/file.txt


ディレクトリ丸ごと



% git rm --cached /path/to/dir


上記を行ってから、add, commit, push します。</description>
        <category>unix:command:git:operation</category>
            <pubDate>Wed, 05 Feb 2014 18:28:55 +0900</pubDate>
        </item>
        <item>
            <title>git :: 過去(特定のリビジョン)の状態を閲覧する</title>
            <link>https://tm.root-n.com/unix:command:git:operation:show_revision</link>
            <description>「ある時点まで存在していたコード片(例えばメソッド等)が、コミットを繰返しているうちに消えていた」場合など、過去のリビジョンを閲覧することで、失ったコード片を取り戻せます。</description>
        <category>unix:command:git:operation</category>
            <pubDate>Thu, 20 Sep 2012 15:36:03 +0900</pubDate>
        </item>
        <item>
            <title>git :: 未 push のコミットを表示する</title>
            <link>https://tm.root-n.com/unix:command:git:operation:uncommit_list</link>
            <description>*  未 push のコミットを表示する


% git log origin/master..HEAD


	*  br1ブランチの場合


% git log origin/br1..HEAD</description>
        <category>unix:command:git:operation</category>
            <pubDate>Sat, 01 Mar 2014 01:58:49 +0900</pubDate>
        </item>
    </channel>
</rss>
