ctrl+z
復原((誤XD$ cat Hello.txt
Hello World from master!
I don't want to commit these messages:
asdwdwoekfmwelkfokmelkf
fwkejneocdeclekmn
wefwejvnweldkcmwl
wefwenweofwel;dfm
wecoiwelwekmfcew
wncwkjnwoeikweofkmwelewnfowef
git add -p Hello.txt
,看會發生什麼!$ git add -p Hello.txt
diff --git a/Hello.txt b/Hello.txt
index e40c200..bcd1f91 100644
--- a/Hello.txt
+++ b/Hello.txt
@@ -1 +1,12 @@
Hello World from master!
+
+
+
+
+I don't want to commit these messages:
+asdwdwoekfmwelkfokmelkf
+fwkejneocdeclekmn
+wefwejvnweldkcmwl
+wefwenweofwel;dfm
+wecoiwelwekmfcew
+wncwkjnwoeikweofkmwelewnfowef
Stage this hunk [y,n,q,a,d,e,?]?
# Manual hunk edit mode -- see bottom for a quick guide.
@@ -1 +1,12 @@
Hello World from master!
+
+
+
+
+I don't want to commit these messages:
+asdwdwoekfmwelkfokmelkf
+fwkejneocdeclekmn
+wefwejvnweldkcmwl
+wefwenweofwel;dfm
+wecoiwelwekmfcew
+wncwkjnwoeikweofkmwelewnfowef
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging.
# If it does not apply cleanly, you will be given an opportunity to
# edit again. If all lines of the hunk are removed, then the edit is
# aborted and the hunk is left unchanged.
# Manual hunk edit mode -- see bottom for a quick guide.
@@ -1 +1,12 @@
Hello World from master!
+
+
+
+
+I don't want to commit these messages:
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
#
# If the patch applies cleanly, the edited hunk will immediately be
# marked for staging.
# If it does not apply cleanly, you will be given an opportunity to
# edit again. If all lines of the hunk are removed, then the edit is
# aborted and the hunk is left unchanged.
git status
!$ git status
On branch master
Your branch is ahead of 'origin/master' by 10 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: Hello.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Hello.txt
上面那個部分的Hello.txt
是你剛剛調整過的檔案,裡面只有兩句話,並且是已經可以直接執行git commit
的!
下面那個部分是還在你的工作目錄的檔案,也就是你原始的檔案(包含你不想要的東西)
這時候只要Commit就可以只Commit部分內容囉~~