..." to update what will be committed">
当前位置:   article > 正文

Git提交与恢复

use "git add ..." to update what will be committed

Git提交与恢复

提交修改

git add --all # 提交所有修改文件
git add file file # 提交部分修改文件

  1. $ git status
  2. On branch master
  3. Your branch is up-to-date with 'origin/master'.
  4. Changes to be committed:
  5. (use "git reset HEAD <file>..." to unstage)
  6. modified: src/Makefile.am
  7. Untracked files:
  8. (use "git add <file>..." to include in what will be committed)
  9. spice-gtk.IAB
  10. spice-gtk.IAD
  11. spice-gtk.IMB
  12. spice-gtk.IMD
  13. spice-gtk.PFI
  14. spice-gtk.PO
  15. spice-gtk.PR
  16. spice-gtk.PRI
  17. spice-gtk.PS
  18. spice-gtk.SearchResults
  19. spice-gtk.WK3
  20. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  21. $ git add --all
  22. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  23. $
回退提交的文件

git reset file # 将执行过git add的某个文件从缓存区恢复到工作文件
git reset -- . # 将执行过git add的所有文件从缓存区恢复到工作文件
git reset --soft id # 将版本回退到对应的commit但保留之后所有commit的修改
git reset --hard id # 将版本回退到对应的commit并放弃之后所有commit的修改

  1. $ git status
  2. On branch master
  3. Your branch is up-to-date with 'origin/master'.
  4. Changes to be committed:
  5. (use "git reset HEAD <file>..." to unstage)
  6. modified: src/Makefile.am
  7. Untracked files:
  8. (use "git add <file>..." to include in what will be committed)
  9. spice-gtk.IAB
  10. spice-gtk.IAD
  11. spice-gtk.IMB
  12. spice-gtk.IMD
  13. spice-gtk.PFI
  14. spice-gtk.PO
  15. spice-gtk.PR
  16. spice-gtk.PRI
  17. spice-gtk.PS
  18. spice-gtk.SearchResults
  19. spice-gtk.WK3
  20. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  21. $ git reset src/Makefile.am
  22. Unstaged changes after reset:
  23. M src/Makefile.am
  24. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  25. $ git status
  26. On branch master
  27. Your branch is up-to-date with 'origin/master'.
  28. Changes not staged for commit:
  29. (use "git add <file>..." to update what will be committed)
  30. (use "git checkout -- <file>..." to discard changes in working directory)
  31. modified: src/Makefile.am
  32. Untracked files:
  33. (use "git add <file>..." to include in what will be committed)
  34. spice-gtk.IAB
  35. spice-gtk.IAD
  36. spice-gtk.IMB
  37. spice-gtk.IMD
  38. spice-gtk.PFI
  39. spice-gtk.PO
  40. spice-gtk.PR
  41. spice-gtk.PRI
  42. spice-gtk.PS
  43. spice-gtk.SearchResults
  44. spice-gtk.WK3
  45. no changes added to commit (use "git add" and/or "git commit -a")
  46. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  47. $ git add --all
  48. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  49. $ git reset -- .
  50. Unstaged changes after reset:
  51. M src/Makefile.am
  52. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  53. $ git status
  54. On branch master
  55. Your branch is up-to-date with 'origin/master'.
  56. Changes not staged for commit:
  57. (use "git add <file>..." to update what will be committed)
  58. (use "git checkout -- <file>..." to discard changes in working directory)
  59. modified: src/Makefile.am
  60. Untracked files:
  61. (use "git add <file>..." to include in what will be committed)
  62. spice-gtk.IAB
  63. spice-gtk.IAD
  64. spice-gtk.IMB
  65. spice-gtk.IMD
  66. spice-gtk.PFI
  67. spice-gtk.PO
  68. spice-gtk.PR
  69. spice-gtk.PRI
  70. spice-gtk.PS
  71. spice-gtk.SearchResults
  72. spice-gtk.WK3
  73. no changes added to commit (use "git add" and/or "git commit -a")
  74. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  75. $ git status
  76. On branch master
  77. Your branch is up-to-date with 'origin/master'.
  78. Changes not staged for commit:
  79. (use "git add <file>..." to update what will be committed)
  80. (use "git checkout -- <file>..." to discard changes in working directory)
  81. modified: src/Makefile.am
  82. Untracked files:
  83. (use "git add <file>..." to include in what will be committed)
  84. spice-gtk.IAB
  85. spice-gtk.IAD
  86. spice-gtk.IMB
  87. spice-gtk.IMD
  88. spice-gtk.PFI
  89. spice-gtk.PO
  90. spice-gtk.PR
  91. spice-gtk.PRI
  92. spice-gtk.PS
  93. spice-gtk.SearchResults
  94. spice-gtk.WK3
  95. no changes added to commit (use "git add" and/or "git commit -a")
  96. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  97. $ git add --all
  98. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  99. $ git commit -m "top"
  100. [master ff418e2] top
  101. 12 files changed, 2 insertions(+)
  102. create mode 100644 spice-gtk.IAB
  103. create mode 100644 spice-gtk.IAD
  104. create mode 100644 spice-gtk.IMB
  105. create mode 100644 spice-gtk.IMD
  106. create mode 100644 spice-gtk.PFI
  107. create mode 100644 spice-gtk.PO
  108. create mode 100644 spice-gtk.PR
  109. create mode 100644 spice-gtk.PRI
  110. create mode 100644 spice-gtk.PS
  111. create mode 100644 spice-gtk.SearchResults
  112. create mode 100644 spice-gtk.WK3
  113. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  114. $ git status
  115. On branch master
  116. Your branch is ahead of 'origin/master' by 1 commit.
  117. (use "git push" to publish your local commits)
  118. nothing to commit, working directory clean
  119. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  120. $ git log
  121. commit ff418e286d14eb75c3cc2227b65e79ccdc8b2b19
  122. Author: silvermagic <fwdssg@gmail.com>
  123. Date: Thu Jun 23 14:41:16 2016 +0800
  124. top
  125. commit 2293b293e83a95a9b939a04a916adf8abed1a100
  126. Author: Takao Fujiwara <tfujiwar@redhat.com>
  127. Date: Fri Apr 15 18:09:37 2016 +0900
  128. Send Hangul key in KR keyboard
  129. Korean keyboard assigns Hangul key on the position of Right Alt and
  130. Left Alt and Hangul keys have the different scancodes but MapVirtualKey()
  131. returned the same scancode and could not use Hangul key on Linux desktop.
  132. The fix is to send the right scancode of VK_HANGUL.
  133. commit 046de27c2eea2b3ee2ade80780f51b2ca140f92d
  134. Author: Takao Fujiwara <tfujiwar@redhat.com>
  135. Date: Fri Apr 15 18:08:37 2016 +0900
  136. Send key release event for some keys in JP keyboard
  137. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  138. $ git reset --soft 2293b293e83a95a9b939a04a916adf8abed1a100
  139. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  140. $ git reset -- .
  141. Unstaged changes after reset:
  142. M src/Makefile.am
  143. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  144. $ git status
  145. On branch master
  146. Your branch is up-to-date with 'origin/master'.
  147. Changes not staged for commit:
  148. (use "git add <file>..." to update what will be committed)
  149. (use "git checkout -- <file>..." to discard changes in working directory)
  150. modified: src/Makefile.am
  151. Untracked files:
  152. (use "git add <file>..." to include in what will be committed)
  153. spice-gtk.IAB
  154. spice-gtk.IAD
  155. spice-gtk.IMB
  156. spice-gtk.IMD
  157. spice-gtk.PFI
  158. spice-gtk.PO
  159. spice-gtk.PR
  160. spice-gtk.PRI
  161. spice-gtk.PS
  162. spice-gtk.SearchResults
  163. spice-gtk.WK3
  164. no changes added to commit (use "git add" and/or "git commit -a")
  165. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  166. $ git add src/Makefile.am
  167. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  168. $ git commit -m "top"
  169. [master 5edeb81] top
  170. 1 file changed, 1 insertion(+)
  171. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  172. $ git status
  173. On branch master
  174. Your branch is ahead of 'origin/master' by 1 commit.
  175. (use "git push" to publish your local commits)
  176. Untracked files:
  177. (use "git add <file>..." to include in what will be committed)
  178. spice-gtk.IAB
  179. spice-gtk.IAD
  180. spice-gtk.IMB
  181. spice-gtk.IMD
  182. spice-gtk.PFI
  183. spice-gtk.PO
  184. spice-gtk.PR
  185. spice-gtk.PRI
  186. spice-gtk.PS
  187. spice-gtk.SearchResults
  188. spice-gtk.WK3
  189. nothing added to commit but untracked files present (use "git add" to track)
  190. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  191. $ git reset --hard 2293b293e83a95a9b939a04a916adf8abed1a100
  192. HEAD is now at 2293b29 Send Hangul key in KR keyboard
  193. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
  194. $ git status
  195. On branch master
  196. Your branch is up-to-date with 'origin/master'.
  197. Untracked files:
  198. (use "git add <file>..." to include in what will be committed)
  199. spice-gtk.IAB
  200. spice-gtk.IAD
  201. spice-gtk.IMB
  202. spice-gtk.IMD
  203. spice-gtk.PFI
  204. spice-gtk.PO
  205. spice-gtk.PR
  206. spice-gtk.PRI
  207. spice-gtk.PS
  208. spice-gtk.SearchResults
  209. spice-gtk.WK3
  210. nothing added to commit but untracked files present (use "git add" to track)
  211. fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
补充修改前一次提交

git commit --amend # 比如前次commit少提交了文件,可以使用git add添加文件,然后使用此命令修改前一次提交

  1. $ git add --all
  2. $ git commit --amend
  3. [master 10e69f0] template
  4. Date: Thu Jul 14 10:51:17 2016 +0800
  5. 4 files changed, 21 insertions(+)
  6. create mode 100644 .gitignore
  7. create mode 100644 CMakeLists.txt
  8. create mode 100644 README.md
  9. create mode 100644 main.c
临时提交和恢复

git stash # 将改动放入缓存区
git stash pop # 取出缓存区存放的内容

打补丁
  1. > git diff from-commit to-commit > diff.patch # 打包修改
  2. > git apply diff.patch # 应用修改

转载于:https://www.cnblogs.com/silvermagic/p/7665844.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/264734?site
推荐阅读
相关标签
  

闽ICP备14008679号