ブクマなドキュメント再読 (3)

大掃除タスクはまだ半分以上残ってますが、今日の部は終了。晩メシおかずの酸辣湯も作成完了。続きに着手します。

とりあえず

Git のアレを試験してみます。なんか gitorious と Tower の試験をしてみたナニがありましたので、これを使ってみる方向。

$ git log --graph
*   commit 6dc7d6894a08112e8470d9f718363bb5708d5355
|\  Merge: 26be78b 79516fe
| | Author: Toshiaki Yamane <t.yamane@example.com>
| | Date:   Mon Nov 29 18:01:55 2010 +0900
| | 
| |     Merge branch 'TextView2Button'
| |   
| * commit 79516fe6bfe20bb80cfe43dcd4604fdb2f1812d9
|/  Author: Toshiaki Yamane <t.yamane@example.com>
|   Date:   Mon Nov 29 17:47:10 2010 +0900
|   
|       from TextView to Button
|  
* commit 26be78bb1145140a6063b2b61f37996bb32cb370
  Author: Toshiaki Yamane <t.yamane@example.com>
  Date:   Mon Nov 29 13:36:08 2010 +0900
  
      first commit
$

現状としては共用リポジトリ (gitorious.org) とローカルの状態は同じなので、ここから Nightly なコミットをローカル側に仕込んで、次が問題なんですが単純に git reset してもっかい commit すれば良いのかなぁ。
ええと、ブランチするのは略でとりあえずボタンクリックなソレを盛り込み。diff は以下で。

$ git diff
diff --git a/.classpath b/.classpath
index 609aa00..6efcbb7 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="src" path="gen"/>
-       <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/res/layout/main.xml b/res/layout/main.xml
index 4540390..da9ef33 100644
--- a/res/layout/main.xml
+++ b/res/layout/main.xml
@@ -5,6 +5,7 @@
     android:layout_height="fill_parent"
     >
 <Button
+       android:id="@+id/btn1"
     Android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello"
diff --git a/src/com/example/hellogit/HelloGitActivity.java b/src/com/example/hellogit/HelloGitActivity.java
index 2c8b029..b78b512 100644
--- a/src/com/example/hellogit/HelloGitActivity.java
+++ b/src/com/example/hellogit/HelloGitActivity.java
@@ -2,6 +2,9 @@ package com.example.hellogit;
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
 
 public class HelloGitActivity extends Activity {
     /** Called when the activity is first created. */
@@ -9,5 +12,14 @@ public class HelloGitActivity extends Activity {
     public void onCreate(Bundle savedInstanceState) {
         setContentView(R.layout.main);
+        
+        Button btn = (Button)findViewById(R.id.btn1);
+        btn.setOnClickListener(new OnClickListener(){
+
+                       public void onClick(View arg0) {
+                               ((Button)arg0).setText("Clicked");
+                       }
+               
+        });
     }
 }
\ No newline at end of file
$

コミットしてみるか。てか、.classpath は ignore します、面倒いので。

$ cat .gitignore
.classpath
bin/
gen/
$ git add .gitignore
$ git add res/layout/main.xml
$ git add src/com/example/hellogit/HelloGitActivity.java
$ git checkout .classpath
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   .gitignore
#       modified:   res/layout/main.xml
#       modified:   src/com/example/hellogit/HelloGitActivity.java
#
$

とりあえず commit します。Nightly#1 で。

$ git commit -m 'Nightly#1'
[master 46fbdb2] Nightly#1
 3 files changed, 14 insertions(+), 0 deletions(-)
$

Toast 出すカンジでもひとつコミットを作ります。diff が以下。

$ git diff
diff --git a/src/com/example/hellogit/HelloGitActivity.java b/src/com/example/hellogit/HelloGitActivity.java
index b78b512..80c452c 100644
--- a/src/com/example/hellogit/HelloGitActivity.java
+++ b/src/com/example/hellogit/HelloGitActivity.java
@@ -5,6 +5,7 @@ import android.os.Bundle;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
+import android.widget.Toast;
 
 public class HelloGitActivity extends Activity {
     /** Called when the activity is first created. */
@@ -17,7 +18,7 @@ public class HelloGitActivity extends Activity {
         btn.setOnClickListener(new OnClickListener(){
 
                        public void onClick(View arg0) {
-                               ((Button)arg0).setText("Clicked");
+                               Toast.makeText(HelloGitActivity.this, "Clicked!", Toast.LENGTH_LONG).show();
                        }
                
         });
$

コミットします。

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   src/com/example/hellogit/HelloGitActivity.java
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git add src/com/example/hellogit/HelloGitActivity.java 
$ git commit -m 'Nightly#2'
[master 8b1a0e8] Nightly#2
 1 files changed, 2 insertions(+), 1 deletions(-)
$

ええと log が以下な模様。

$ git log --graph
* commit 8b1a0e8bcf106fe80899d9d00deb5d775d7bbda5
| Author: Toshiaki Yamane <t.yamane@example.com>
| Date:   Wed Dec 29 20:01:59 2010 +0900
| 
|     Nightly#2
|  
* commit 46fbdb20bddf7562bf412ae6f218555bd7bba32a
| Author: Toshiaki Yamane <t.yamane@example.com>
| Date:   Wed Dec 29 19:44:41 2010 +0900
| 
|     Nightly#1
|    
*   commit 6dc7d6894a08112e8470d9f718363bb5708d5355
|\  Merge: 26be78b 79516fe
| | Author: Toshiaki Yamane <t.yamane@example.com>
| | Date:   Mon Nov 29 18:01:55 2010 +0900
| | 
| |     Merge branch 'TextView2Button'
| |   
| * commit 79516fe6bfe20bb80cfe43dcd4604fdb2f1812d9
|/  Author: Toshiaki Yamane <t.yamane@example.com>
|   Date:   Mon Nov 29 17:47:10 2010 +0900
|   
|       from TextView to Button
|  
* commit 26be78bb1145140a6063b2b61f37996bb32cb370
  Author: Toshiaki Yamane <t.yamane@example.com>
  Date:   Mon Nov 29 13:36:08 2010 +0900
  
      first commit
$

ここで git reset --hard origin/master したらどうなるか。

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
$ git reset --hard origin/master
HEAD is now at 6dc7d68 Merge branch 'TextView2Button'
$

む、巻き戻った?
ええと、git log -g で良いのかな。

commit 6dc7d6894a08112e8470d9f718363bb5708d5355
Reflog: HEAD@{0} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: origin/master: updating HEAD
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 18:01:55 2010 +0900

    Merge branch 'TextView2Button'

commit 8b1a0e8bcf106fe80899d9d00deb5d775d7bbda5
Reflog: HEAD@{1} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: commit: Nightly#2
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Wed Dec 29 20:01:59 2010 +0900

    Nightly#2

commit 46fbdb20bddf7562bf412ae6f218555bd7bba32a
Reflog: HEAD@{2} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: commit: Nightly#1
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Wed Dec 29 19:44:41 2010 +0900

    Nightly#1

commit 6dc7d6894a08112e8470d9f718363bb5708d5355
Reflog: HEAD@{3} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: merge TextView2Button: Merge made by recursive.
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 18:01:55 2010 +0900

    Merge branch 'TextView2Button'

commit 26be78bb1145140a6063b2b61f37996bb32cb370
Reflog: HEAD@{4} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: checkout: moving from TextView2Button to master
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 13:36:08 2010 +0900

    first commit

commit 79516fe6bfe20bb80cfe43dcd4604fdb2f1812d9
Reflog: HEAD@{5} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: checkout: moving from master to TextView2Button
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 17:47:10 2010 +0900

    from TextView to Button

commit 26be78bb1145140a6063b2b61f37996bb32cb370
Reflog: HEAD@{6} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: checkout: moving from TextView2Button to master
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 13:36:08 2010 +0900

    first commit

commit 79516fe6bfe20bb80cfe43dcd4604fdb2f1812d9
Reflog: HEAD@{7} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: commit: from TextView to Button
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 17:47:10 2010 +0900

    from TextView to Button

commit 26be78bb1145140a6063b2b61f37996bb32cb370
Reflog: HEAD@{8} (Toshiaki Yamane <t.yamane@example.com>)
Reflog message: checkout: moving from master to TextView2Button
Author: Toshiaki Yamane <t.yamane@example.com>
Date:   Mon Nov 29 13:36:08 2010 +0900

    first commit

$

しかしこの状態ではどうにもならんな。てか、元エントリの gitk の出力の意味が分からんな。てーか、どう見ても Nightly なソレは branch しているように見えます。面倒臭いけどもっかいヤッてみるか。でも、どうやって v4 な commit を作れば良いのやら。
そもそも Nightly なナニが一日毎にその前の日を引き継がない形で出現するってのも微妙。

revert すれば良いの? git revert HEAD してみます。

$ git revert HEAD
fatal: Commit 6dc7d6894a08112e8470d9f718363bb5708d5355 is a merge but no -m option was given.
$
  • m って何だば。てか、どんな経緯かは不明ですが commit な id 指定で云々したら以下なメセジが出力される。
$ git revert 8b1a0e8bcf106fe80899d9d00deb5d775d7bbda5
fatal: 'revert' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
$

げ、何だこれは。diff 見てみたら以下。

$ git diff
diff --cc src/com/example/hellogit/HelloGitActivity.java
index 2c8b029,b78b512..0000000
--- a/src/com/example/hellogit/HelloGitActivity.java
+++ b/src/com/example/hellogit/HelloGitActivity.java
@@@ -2,6 -2,9 +2,12 @@@ package com.example.hellogit
  
  import android.app.Activity;
  import android.os.Bundle;
++<<<<<<< HEAD
++=======
+ import android.view.View;
+ import android.view.View.OnClickListener;
+ import android.widget.Button;
++>>>>>>> parent of 8b1a0e8... Nightly#2
  
  public class HelloGitActivity extends Activity {
      /** Called when the activity is first created. */
@@@ -9,5 -12,14 +15,17 @@@
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
++<<<<<<< HEAD
++=======
+         
+         Button btn = (Button)findViewById(R.id.btn1);
+         btn.setOnClickListener(new OnClickListener(){
+ 
+                       public void onClick(View arg0) {
+                               ((Button)arg0).setText("Clicked");
+                       }
+               
+         });
++>>>>>>> parent of 8b1a0e8... Nightly#2
      }
  }
$

ええと、この conflict を解消してコミット入れたらどうなるのかな。なんとなく解決が微妙ですな。res/layout/main.xml な修正が範疇外だなぁ。

結論

とりあえず reset --hard して revert するのはありなのかもしれませんが、今回は失敗って事で。