Gitでファイルの一部だけ元に戻す

目的

git diffしたらあるファイルのいくつかの修正のうち一部だけ戻したくなった

$ git diff BookPanel.cs
diff --git a/BookPanel.cs b/BookPanel.cs
index 01631d1..01a3623 100644
--- a/BookPanel.cs
+++ b/BookPanel.cs
@@ -1,4 +1,5 @@
-<U+FEFF>using System.Collections;
+<U+FEFF>using System;
+using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
@@ -7,16 +8,10 @@ public class BookPanel : MonoBehaviour {
 
        // Use this for initialization
        void Start () {
-        GetInputFieldComponent("Title").text = Storage.GetBookTitle();
-        var wordsPerLineText = Storage.GetWordsPerLine();
-        GetInputFieldComponent("WordsPerLine").text = wordsPerLineText;
-        UpdateMetronome(wordsPerLineText);
-
-        var library = Storage.GetLibrary();
-        if (library.Books != null && library.Books.Count != 0)
-        {
-            var book = library.Books[0];
-        }
+        var book = Storage.GetLibrary().Books[0];
+        GetInputFieldComponent("Title").text = book.Title;
+        GetInputFieldComponent("WordsPerLine").text = book.WordsPerLine.ToString();
+        UpdateMetronome(book.WordsPerLine);
        }
        
        // Update is called once per frame
@@ -33,11 +28,17 @@ public class BookPanel : MonoBehaviour {
     public void OnEndEditWordsPerLine()
     {
         var wordsPerLineText = GetInputFieldComponent("WordsPerLine").text;
+        var wordsPerLine = 1.0f;
+        try
+        {
+            wordsPerLine = float.Parse(wordsPerLineText);
+        }
+        catch (FormatException)
+        {
+            // Use initial value
+        }
         Storage.SetWordsPerLine(wordsPerLineText);
-
-        var t = GameObject.Find("TimerX").GetComponent<TimerX>();
-        t.SetWordsPerLine(wordsPerLineText);
-        UpdateMetronome(wordsPerLineText);
+        UpdateMetronome(wordsPerLine);
         SaveBook();
     }
 ```

二ヶ所目のパッチだけ戻したい

# 方法

そういう時は、こうすればいい

git checkout -p BookPanel.cs

「このhunkを作業ツリーから捨てるか」というプロンプトが出てくるので、yとかnとか答える

Discard this hunk from worktree [y,n,q,a,d,/,K,j,J,g,e,?]?