logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

git-reset.1 (24596B)


  1. '\" t
  2. .\" Title: git-reset
  3. .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
  4. .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
  5. .\" Date: 2025-03-14
  6. .\" Manual: Git Manual
  7. .\" Source: Git 2.49.0
  8. .\" Language: English
  9. .\"
  10. .TH "GIT\-RESET" "1" "2025-03-14" "Git 2\&.49\&.0" "Git Manual"
  11. .\" -----------------------------------------------------------------
  12. .\" * Define some portability stuff
  13. .\" -----------------------------------------------------------------
  14. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. .\" http://bugs.debian.org/507673
  16. .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
  17. .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. .ie \n(.g .ds Aq \(aq
  19. .el .ds Aq '
  20. .\" -----------------------------------------------------------------
  21. .\" * set default formatting
  22. .\" -----------------------------------------------------------------
  23. .\" disable hyphenation
  24. .nh
  25. .\" disable justification (adjust text to left margin only)
  26. .ad l
  27. .\" -----------------------------------------------------------------
  28. .\" * MAIN CONTENT STARTS HERE *
  29. .\" -----------------------------------------------------------------
  30. .SH "NAME"
  31. git-reset \- Reset current HEAD to the specified state
  32. .SH "SYNOPSIS"
  33. .sp
  34. .nf
  35. \fIgit reset\fR [\-q] [<tree\-ish>] [\-\-] <pathspec>\&...\:
  36. \fIgit reset\fR [\-q] [\-\-pathspec\-from\-file=<file> [\-\-pathspec\-file\-nul]] [<tree\-ish>]
  37. \fIgit reset\fR (\-\-patch | \-p) [<tree\-ish>] [\-\-] [<pathspec>\&...\:]
  38. \fIgit reset\fR [\-\-soft | \-\-mixed [\-N] | \-\-hard | \-\-merge | \-\-keep] [\-q] [<commit>]
  39. .fi
  40. .SH "DESCRIPTION"
  41. .sp
  42. In the first three forms, copy entries from \fI<tree\-ish>\fR to the index\&. In the last form, set the current branch head (\fBHEAD\fR) to \fI<commit>\fR, optionally modifying index and working tree to match\&. The \fI<tree\-ish>\fR/\fI<commit>\fR defaults to \fBHEAD\fR in all forms\&.
  43. .PP
  44. \fIgit reset\fR [\-q] [<tree\-ish>] [\-\-] <pathspec>\&...\:, \fIgit reset\fR [\-q] [\-\-pathspec\-from\-file=<file> [\-\-pathspec\-file\-nul]] [<tree\-ish>]
  45. .RS 4
  46. These forms reset the index entries for all paths that match the
  47. \fI<pathspec>\fR
  48. to their state at
  49. \fI<tree\-ish>\fR\&. (It does not affect the working tree or the current branch\&.)
  50. .sp
  51. This means that
  52. \fBgit\fR
  53. \fBreset\fR
  54. \fI<pathspec>\fR
  55. is the opposite of
  56. \fBgit\fR
  57. \fBadd\fR
  58. \fI<pathspec>\fR\&. This command is equivalent to
  59. \fBgit\fR
  60. \fBrestore\fR
  61. [\fB\-\-source=\fR\fI<tree\-ish>\fR]
  62. \fB\-\-staged\fR
  63. \fI<pathspec>\fR\&.\&.\&.\&.
  64. .sp
  65. After running
  66. \fBgit\fR
  67. \fBreset\fR
  68. \fI<pathspec>\fR
  69. to update the index entry, you can use
  70. \fBgit-restore\fR(1)
  71. to check the contents out of the index to the working tree\&. Alternatively, using
  72. \fBgit-restore\fR(1)
  73. and specifying a commit with
  74. \fB\-\-source\fR, you can copy the contents of a path out of a commit to the index and to the working tree in one go\&.
  75. .RE
  76. .PP
  77. \fIgit reset\fR (\-\-patch | \-p) [<tree\-ish>] [\-\-] [<pathspec>\&...\:]
  78. .RS 4
  79. Interactively select hunks in the difference between the index and
  80. \fI<tree\-ish>\fR
  81. (defaults to
  82. \fBHEAD\fR)\&. The chosen hunks are applied in reverse to the index\&.
  83. .sp
  84. This means that
  85. \fBgit\fR
  86. \fBreset\fR
  87. \fB\-p\fR
  88. is the opposite of
  89. \fBgit\fR
  90. \fBadd\fR
  91. \fB\-p\fR, i\&.e\&. you can use it to selectively reset hunks\&. See the
  92. \(lqInteractive Mode\(rq
  93. section of
  94. \fBgit-add\fR(1)
  95. to learn how to operate the
  96. \fB\-\-patch\fR
  97. mode\&.
  98. .RE
  99. .PP
  100. \fIgit reset\fR [<mode>] [<commit>]
  101. .RS 4
  102. This form resets the current branch head to
  103. \fI<commit>\fR
  104. and possibly updates the index (resetting it to the tree of
  105. \fI<commit>\fR) and the working tree depending on
  106. \fI<mode>\fR\&. Before the operation,
  107. \fBORIG_HEAD\fR
  108. is set to the tip of the current branch\&. If
  109. \fI<mode>\fR
  110. is omitted, defaults to
  111. \fB\-\-mixed\fR\&. The
  112. \fI<mode>\fR
  113. must be one of the following:
  114. .PP
  115. \-\-soft
  116. .RS 4
  117. Does not touch the index file or the working tree at all (but resets the head to
  118. \fI<commit>\fR, just like all modes do)\&. This leaves all your changed files "Changes to be committed", as
  119. \fBgit\fR
  120. \fBstatus\fR
  121. would put it\&.
  122. .RE
  123. .PP
  124. \-\-mixed
  125. .RS 4
  126. Resets the index but not the working tree (i\&.e\&., the changed files are preserved but not marked for commit) and reports what has not been updated\&. This is the default action\&.
  127. .sp
  128. If
  129. \fB\-N\fR
  130. is specified, removed paths are marked as intent\-to\-add (see
  131. \fBgit-add\fR(1))\&.
  132. .RE
  133. .PP
  134. \-\-hard
  135. .RS 4
  136. Resets the index and working tree\&. Any changes to tracked files in the working tree since
  137. \fI<commit>\fR
  138. are discarded\&. Any untracked files or directories in the way of writing any tracked files are simply deleted\&.
  139. .RE
  140. .PP
  141. \-\-merge
  142. .RS 4
  143. Resets the index and updates the files in the working tree that are different between
  144. \fI<commit>\fR
  145. and
  146. \fBHEAD\fR, but keeps those which are different between the index and working tree (i\&.e\&. which have changes which have not been added)\&. If a file that is different between
  147. \fI<commit>\fR
  148. and the index has unstaged changes, reset is aborted\&.
  149. .sp
  150. In other words,
  151. \fB\-\-merge\fR
  152. does something like a
  153. \fBgit\fR
  154. \fBread\-tree\fR
  155. \fB\-u\fR
  156. \fB\-m\fR
  157. \fI<commit>\fR, but carries forward unmerged index entries\&.
  158. .RE
  159. .PP
  160. \-\-keep
  161. .RS 4
  162. Resets index entries and updates files in the working tree that are different between
  163. \fI<commit>\fR
  164. and
  165. \fBHEAD\fR\&. If a file that is different between
  166. \fI<commit>\fR
  167. and
  168. \fBHEAD\fR
  169. has local changes, reset is aborted\&.
  170. .RE
  171. .PP
  172. \-\-[no\-]recurse\-submodules
  173. .RS 4
  174. When the working tree is updated, using \-\-recurse\-submodules will also recursively reset the working tree of all active submodules according to the commit recorded in the superproject, also setting the submodules\*(Aq HEAD to be detached at that commit\&.
  175. .RE
  176. .RE
  177. .sp
  178. See "Reset, restore and revert" in \fBgit\fR(1) for the differences between the three commands\&.
  179. .SH "OPTIONS"
  180. .PP
  181. \-q, \-\-quiet
  182. .RS 4
  183. Be quiet, only report errors\&.
  184. .RE
  185. .PP
  186. \-\-refresh, \-\-no\-refresh
  187. .RS 4
  188. Refresh the index after a mixed reset\&. Enabled by default\&.
  189. .RE
  190. .PP
  191. \-\-pathspec\-from\-file=<file>
  192. .RS 4
  193. Pathspec is passed in
  194. \fI<file>\fR
  195. instead of commandline args\&. If
  196. \fI<file>\fR
  197. is exactly
  198. \fB\-\fR
  199. then standard input is used\&. Pathspec elements are separated by LF or CR/LF\&. Pathspec elements can be quoted as explained for the configuration variable
  200. \fBcore\&.quotePath\fR
  201. (see
  202. \fBgit-config\fR(1))\&. See also
  203. \fB\-\-pathspec\-file\-nul\fR
  204. and global
  205. \fB\-\-literal\-pathspecs\fR\&.
  206. .RE
  207. .PP
  208. \-\-pathspec\-file\-nul
  209. .RS 4
  210. Only meaningful with
  211. \fB\-\-pathspec\-from\-file\fR\&. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes)\&.
  212. .RE
  213. .PP
  214. \-\-
  215. .RS 4
  216. Do not interpret any more arguments as options\&.
  217. .RE
  218. .PP
  219. <pathspec>\&...\:
  220. .RS 4
  221. Limits the paths affected by the operation\&.
  222. .sp
  223. For more details, see the
  224. \fIpathspec\fR
  225. entry in
  226. \fBgitglossary\fR(7)\&.
  227. .RE
  228. .SH "EXAMPLES"
  229. .PP
  230. Undo add
  231. .RS 4
  232. .sp
  233. .if n \{\
  234. .RS 4
  235. .\}
  236. .nf
  237. $ edit \fB(1)\fR
  238. $ git add frotz\&.c filfre\&.c
  239. $ mailx \fB(2)\fR
  240. $ git reset \fB(3)\fR
  241. $ git pull git://info\&.example\&.com/ nitfol \fB(4)\fR
  242. .fi
  243. .if n \{\
  244. .RE
  245. .\}
  246. .TS
  247. tab(:);
  248. r lw(\n(.lu*75u/100u).
  249. \fB1.\fR\h'-2n':T{
  250. You are happily working on something, and find the changes in these files are in good order\&. You do not want to see them when you run
  251. \fBgit\fR
  252. \fBdiff\fR, because you plan to work on other files and changes with these files are distracting\&.
  253. T}
  254. \fB2.\fR\h'-2n':T{
  255. Somebody asks you to pull, and the changes sound worthy of merging\&.
  256. T}
  257. \fB3.\fR\h'-2n':T{
  258. However, you already dirtied the index (i\&.e\&. your index does not match the
  259. \fBHEAD\fR
  260. commit)\&. But you know the pull you are going to make does not affect
  261. \fBfrotz\&.c\fR
  262. or
  263. \fBfilfre\&.c\fR, so you revert the index changes for these two files\&. Your changes in working tree remain there\&.
  264. T}
  265. \fB4.\fR\h'-2n':T{
  266. Then you can pull and merge, leaving
  267. \fBfrotz\&.c\fR
  268. and
  269. \fBfilfre\&.c\fR
  270. changes still in the working tree\&.
  271. T}
  272. .TE
  273. .RE
  274. .PP
  275. Undo a commit and redo
  276. .RS 4
  277. .sp
  278. .if n \{\
  279. .RS 4
  280. .\}
  281. .nf
  282. $ git commit \&.\&.\&.
  283. $ git reset \-\-soft HEAD^ \fB(1)\fR
  284. $ edit \fB(2)\fR
  285. $ git commit \-a \-c ORIG_HEAD \fB(3)\fR
  286. .fi
  287. .if n \{\
  288. .RE
  289. .\}
  290. .TS
  291. tab(:);
  292. r lw(\n(.lu*75u/100u).
  293. \fB1.\fR\h'-2n':T{
  294. This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both\&. Leaves working tree as it was before "reset"\&.
  295. T}
  296. \fB2.\fR\h'-2n':T{
  297. Make corrections to working tree files\&.
  298. T}
  299. \fB3.\fR\h'-2n':T{
  300. "reset" copies the old head to \&.\fBgit/ORIG_HEAD\fR; redo the commit by starting with its log message\&. If you do not need to edit the message further, you can give
  301. \fB\-C\fR
  302. option instead\&.
  303. .sp
  304. See also the
  305. \fB\-\-amend\fR
  306. option to
  307. \fBgit-commit\fR(1)\&.
  308. T}
  309. .TE
  310. .RE
  311. .PP
  312. Undo a commit, making it a topic branch
  313. .RS 4
  314. .sp
  315. .if n \{\
  316. .RS 4
  317. .\}
  318. .nf
  319. $ git branch topic/wip \fB(1)\fR
  320. $ git reset \-\-hard HEAD~3 \fB(2)\fR
  321. $ git switch topic/wip \fB(3)\fR
  322. .fi
  323. .if n \{\
  324. .RE
  325. .\}
  326. .TS
  327. tab(:);
  328. r lw(\n(.lu*75u/100u).
  329. \fB1.\fR\h'-2n':T{
  330. You have made some commits, but realize they were premature to be in the
  331. \fBmaster\fR
  332. branch\&. You want to continue polishing them in a topic branch, so create
  333. \fBtopic/wip\fR
  334. branch off of the current
  335. \fBHEAD\fR\&.
  336. T}
  337. \fB2.\fR\h'-2n':T{
  338. Rewind the master branch to get rid of those three commits\&.
  339. T}
  340. \fB3.\fR\h'-2n':T{
  341. Switch to
  342. \fBtopic/wip\fR
  343. branch and keep working\&.
  344. T}
  345. .TE
  346. .RE
  347. .PP
  348. Undo commits permanently
  349. .RS 4
  350. .sp
  351. .if n \{\
  352. .RS 4
  353. .\}
  354. .nf
  355. $ git commit \&.\&.\&.
  356. $ git reset \-\-hard HEAD~3 \fB(1)\fR
  357. .fi
  358. .if n \{\
  359. .RE
  360. .\}
  361. .TS
  362. tab(:);
  363. r lw(\n(.lu*75u/100u).
  364. \fB1.\fR\h'-2n':T{
  365. The last three commits (\fBHEAD\fR,
  366. \fBHEAD^\fR, and
  367. \fBHEAD~2\fR) were bad and you do not want to ever see them again\&. Do
  368. \fBnot\fR
  369. do this if you have already given these commits to somebody else\&. (See the "RECOVERING FROM UPSTREAM REBASE" section in
  370. \fBgit-rebase\fR(1)
  371. for the implications of doing so\&.)
  372. T}
  373. .TE
  374. .RE
  375. .PP
  376. Undo a merge or pull
  377. .RS 4
  378. .sp
  379. .if n \{\
  380. .RS 4
  381. .\}
  382. .nf
  383. $ git pull \fB(1)\fR
  384. Auto\-merging nitfol
  385. CONFLICT (content): Merge conflict in nitfol
  386. Automatic merge failed; fix conflicts and then commit the result\&.
  387. $ git reset \-\-hard \fB(2)\fR
  388. $ git pull \&. topic/branch \fB(3)\fR
  389. Updating from 41223\&.\&.\&. to 13134\&.\&.\&.
  390. Fast\-forward
  391. $ git reset \-\-hard ORIG_HEAD \fB(4)\fR
  392. .fi
  393. .if n \{\
  394. .RE
  395. .\}
  396. .TS
  397. tab(:);
  398. r lw(\n(.lu*75u/100u).
  399. \fB1.\fR\h'-2n':T{
  400. Try to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later\&.
  401. T}
  402. \fB2.\fR\h'-2n':T{
  403. "pull" has not made merge commit, so
  404. \fBgit\fR
  405. \fBreset\fR
  406. \fB\-\-hard\fR
  407. which is a synonym for
  408. \fBgit\fR
  409. \fBreset\fR
  410. \fB\-\-hard\fR
  411. \fBHEAD\fR
  412. clears the mess from the index file and the working tree\&.
  413. T}
  414. \fB3.\fR\h'-2n':T{
  415. Merge a topic branch into the current branch, which resulted in a fast\-forward\&.
  416. T}
  417. \fB4.\fR\h'-2n':T{
  418. But you decided that the topic branch is not ready for public consumption yet\&. "pull" or "merge" always leaves the original tip of the current branch in
  419. \fBORIG_HEAD\fR, so resetting hard to it brings your index file and the working tree back to that state, and resets the tip of the branch to that commit\&.
  420. T}
  421. .TE
  422. .RE
  423. .PP
  424. Undo a merge or pull inside a dirty working tree
  425. .RS 4
  426. .sp
  427. .if n \{\
  428. .RS 4
  429. .\}
  430. .nf
  431. $ git pull \fB(1)\fR
  432. Auto\-merging nitfol
  433. Merge made by recursive\&.
  434. nitfol | 20 +++++\-\-\-\-
  435. \&.\&.\&.
  436. $ git reset \-\-merge ORIG_HEAD \fB(2)\fR
  437. .fi
  438. .if n \{\
  439. .RE
  440. .\}
  441. .TS
  442. tab(:);
  443. r lw(\n(.lu*75u/100u).
  444. \fB1.\fR\h'-2n':T{
  445. Even if you may have local modifications in your working tree, you can safely say
  446. \fBgit\fR
  447. \fBpull\fR
  448. when you know that the change in the other branch does not overlap with them\&.
  449. T}
  450. \fB2.\fR\h'-2n':T{
  451. After inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory\&. Running
  452. \fBgit\fR
  453. \fBreset\fR
  454. \fB\-\-hard\fR
  455. \fBORIG_HEAD\fR
  456. will let you go back to where you were, but it will discard your local changes, which you do not want\&.
  457. \fBgit\fR
  458. \fBreset\fR
  459. \fB\-\-merge\fR
  460. keeps your local changes\&.
  461. T}
  462. .TE
  463. .RE
  464. .PP
  465. Interrupted workflow
  466. .RS 4
  467. Suppose you are interrupted by an urgent fix request while you are in the middle of a large change\&. The files in your working tree are not in any shape to be committed yet, but you need to get to the other branch for a quick bugfix\&.
  468. .sp
  469. .if n \{\
  470. .RS 4
  471. .\}
  472. .nf
  473. $ git switch feature ;# you were working in "feature" branch and
  474. $ work work work ;# got interrupted
  475. $ git commit \-a \-m "snapshot WIP" \fB(1)\fR
  476. $ git switch master
  477. $ fix fix fix
  478. $ git commit ;# commit with real log
  479. $ git switch feature
  480. $ git reset \-\-soft HEAD^ ;# go back to WIP state \fB(2)\fR
  481. $ git reset \fB(3)\fR
  482. .fi
  483. .if n \{\
  484. .RE
  485. .\}
  486. .TS
  487. tab(:);
  488. r lw(\n(.lu*75u/100u).
  489. \fB1.\fR\h'-2n':T{
  490. This commit will get blown away so a throw\-away log message is OK\&.
  491. T}
  492. \fB2.\fR\h'-2n':T{
  493. This removes the
  494. \fIWIP\fR
  495. commit from the commit history, and sets your working tree to the state just before you made that snapshot\&.
  496. T}
  497. \fB3.\fR\h'-2n':T{
  498. At this point the index file still has all the WIP changes you committed as
  499. \fIsnapshot WIP\fR\&. This updates the index to show your WIP files as uncommitted\&.
  500. .sp
  501. See also
  502. \fBgit-stash\fR(1)\&.
  503. T}
  504. .TE
  505. .RE
  506. .PP
  507. Reset a single file in the index
  508. .RS 4
  509. Suppose you have added a file to your index, but later decide you do not want to add it to your commit\&. You can remove the file from the index while keeping your changes with git reset\&.
  510. .sp
  511. .if n \{\
  512. .RS 4
  513. .\}
  514. .nf
  515. $ git reset \-\- frotz\&.c \fB(1)\fR
  516. $ git commit \-m "Commit files in index" \fB(2)\fR
  517. $ git add frotz\&.c \fB(3)\fR
  518. .fi
  519. .if n \{\
  520. .RE
  521. .\}
  522. .TS
  523. tab(:);
  524. r lw(\n(.lu*75u/100u).
  525. \fB1.\fR\h'-2n':T{
  526. This removes the file from the index while keeping it in the working directory\&.
  527. T}
  528. \fB2.\fR\h'-2n':T{
  529. This commits all other changes in the index\&.
  530. T}
  531. \fB3.\fR\h'-2n':T{
  532. Adds the file to the index again\&.
  533. T}
  534. .TE
  535. .RE
  536. .PP
  537. Keep changes in working tree while discarding some previous commits
  538. .RS 4
  539. Suppose you are working on something and you commit it, and then you continue working a bit more, but now you think that what you have in your working tree should be in another branch that has nothing to do with what you committed previously\&. You can start a new branch and reset it while keeping the changes in your working tree\&.
  540. .sp
  541. .if n \{\
  542. .RS 4
  543. .\}
  544. .nf
  545. $ git tag start
  546. $ git switch \-c branch1
  547. $ edit
  548. $ git commit \&.\&.\&. \fB(1)\fR
  549. $ edit
  550. $ git switch \-c branch2 \fB(2)\fR
  551. $ git reset \-\-keep start \fB(3)\fR
  552. .fi
  553. .if n \{\
  554. .RE
  555. .\}
  556. .TS
  557. tab(:);
  558. r lw(\n(.lu*75u/100u).
  559. \fB1.\fR\h'-2n':T{
  560. This commits your first edits in
  561. \fBbranch1\fR\&.
  562. T}
  563. \fB2.\fR\h'-2n':T{
  564. In the ideal world, you could have realized that the earlier commit did not belong to the new topic when you created and switched to
  565. \fBbranch2\fR
  566. (i\&.e\&.
  567. \fBgit\fR
  568. \fBswitch\fR
  569. \fB\-c\fR
  570. \fBbranch2\fR
  571. \fBstart\fR), but nobody is perfect\&.
  572. T}
  573. \fB3.\fR\h'-2n':T{
  574. But you can use
  575. \fBreset\fR
  576. \fB\-\-keep\fR
  577. to remove the unwanted commit after you switched to
  578. \fBbranch2\fR\&.
  579. T}
  580. .TE
  581. .RE
  582. .PP
  583. Split a commit apart into a sequence of commits
  584. .RS 4
  585. Suppose that you have created lots of logically separate changes and committed them together\&. Then, later you decide that it might be better to have each logical chunk associated with its own commit\&. You can use git reset to rewind history without changing the contents of your local files, and then successively use
  586. \fBgit\fR
  587. \fBadd\fR
  588. \fB\-p\fR
  589. to interactively select which hunks to include into each commit, using
  590. \fBgit\fR
  591. \fBcommit\fR
  592. \fB\-c\fR
  593. to pre\-populate the commit message\&.
  594. .sp
  595. .if n \{\
  596. .RS 4
  597. .\}
  598. .nf
  599. $ git reset \-N HEAD^ \fB(1)\fR
  600. $ git add \-p \fB(2)\fR
  601. $ git diff \-\-cached \fB(3)\fR
  602. $ git commit \-c HEAD@{1} \fB(4)\fR
  603. \&.\&.\&. \fB(5)\fR
  604. $ git add \&.\&.\&. \fB(6)\fR
  605. $ git diff \-\-cached \fB(7)\fR
  606. $ git commit \&.\&.\&. \fB(8)\fR
  607. .fi
  608. .if n \{\
  609. .RE
  610. .\}
  611. .TS
  612. tab(:);
  613. r lw(\n(.lu*75u/100u).
  614. \fB1.\fR\h'-2n':T{
  615. First, reset the history back one commit so that we remove the original commit, but leave the working tree with all the changes\&. The \-N ensures that any new files added with
  616. \fBHEAD\fR
  617. are still marked so that
  618. \fBgit\fR
  619. \fBadd\fR
  620. \fB\-p\fR
  621. will find them\&.
  622. T}
  623. \fB2.\fR\h'-2n':T{
  624. Next, we interactively select diff hunks to add using the
  625. \fBgit\fR
  626. \fBadd\fR
  627. \fB\-p\fR
  628. facility\&. This will ask you about each diff hunk in sequence and you can use simple commands such as "yes, include this", "No don\(cqt include this" or even the very powerful "edit" facility\&.
  629. T}
  630. \fB3.\fR\h'-2n':T{
  631. Once satisfied with the hunks you want to include, you should verify what has been prepared for the first commit by using
  632. \fBgit\fR
  633. \fBdiff\fR
  634. \fB\-\-cached\fR\&. This shows all the changes that have been moved into the index and are about to be committed\&.
  635. T}
  636. \fB4.\fR\h'-2n':T{
  637. Next, commit the changes stored in the index\&. The
  638. \fB\-c\fR
  639. option specifies to pre\-populate the commit message from the original message that you started with in the first commit\&. This is helpful to avoid retyping it\&. The
  640. \fBHEAD@\fR{1} is a special notation for the commit that
  641. \fBHEAD\fR
  642. used to be at prior to the original reset commit (1 change ago)\&. See
  643. \fBgit-reflog\fR(1)
  644. for more details\&. You may also use any other valid commit reference\&.
  645. T}
  646. \fB5.\fR\h'-2n':T{
  647. You can repeat steps 2\-4 multiple times to break the original code into any number of commits\&.
  648. T}
  649. \fB6.\fR\h'-2n':T{
  650. Now you\(cqve split out many of the changes into their own commits, and might no longer use the patch mode of
  651. \fBgit\fR
  652. \fBadd\fR, in order to select all remaining uncommitted changes\&.
  653. T}
  654. \fB7.\fR\h'-2n':T{
  655. Once again, check to verify that you\(cqve included what you want to\&. You may also wish to verify that git diff doesn\(cqt show any remaining changes to be committed later\&.
  656. T}
  657. \fB8.\fR\h'-2n':T{
  658. And finally create the final commit\&.
  659. T}
  660. .TE
  661. .RE
  662. .SH "DISCUSSION"
  663. .sp
  664. The tables below show what happens when running:
  665. .sp
  666. .if n \{\
  667. .RS 4
  668. .\}
  669. .nf
  670. git reset \-\-option target
  671. .fi
  672. .if n \{\
  673. .RE
  674. .\}
  675. .sp
  676. to reset the \fBHEAD\fR to another commit (\fBtarget\fR) with the different reset options depending on the state of the files\&.
  677. .sp
  678. In these tables, \fBA\fR, \fBB\fR, \fBC\fR and \fBD\fR are some different states of a file\&. For example, the first line of the first table means that if a file is in state \fBA\fR in the working tree, in state \fBB\fR in the index, in state \fBC\fR in \fBHEAD\fR and in state \fBD\fR in the target, then \fBgit\fR \fBreset\fR \fB\-\-soft\fR \fBtarget\fR will leave the file in the working tree in state \fBA\fR and in the index in state \fBB\fR\&. It resets (i\&.e\&. moves) the \fBHEAD\fR (i\&.e\&. the tip of the current branch, if you are on one) to \fBtarget\fR (which has the file in state \fBD\fR)\&.
  679. .sp
  680. .if n \{\
  681. .RS 4
  682. .\}
  683. .nf
  684. working index HEAD target working index HEAD
  685. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  686. A B C D \-\-soft A B D
  687. \-\-mixed A D D
  688. \-\-hard D D D
  689. \-\-merge (disallowed)
  690. \-\-keep (disallowed)
  691. .fi
  692. .if n \{\
  693. .RE
  694. .\}
  695. .sp
  696. .if n \{\
  697. .RS 4
  698. .\}
  699. .nf
  700. working index HEAD target working index HEAD
  701. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  702. A B C C \-\-soft A B C
  703. \-\-mixed A C C
  704. \-\-hard C C C
  705. \-\-merge (disallowed)
  706. \-\-keep A C C
  707. .fi
  708. .if n \{\
  709. .RE
  710. .\}
  711. .sp
  712. .if n \{\
  713. .RS 4
  714. .\}
  715. .nf
  716. working index HEAD target working index HEAD
  717. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  718. B B C D \-\-soft B B D
  719. \-\-mixed B D D
  720. \-\-hard D D D
  721. \-\-merge D D D
  722. \-\-keep (disallowed)
  723. .fi
  724. .if n \{\
  725. .RE
  726. .\}
  727. .sp
  728. .if n \{\
  729. .RS 4
  730. .\}
  731. .nf
  732. working index HEAD target working index HEAD
  733. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  734. B B C C \-\-soft B B C
  735. \-\-mixed B C C
  736. \-\-hard C C C
  737. \-\-merge C C C
  738. \-\-keep B C C
  739. .fi
  740. .if n \{\
  741. .RE
  742. .\}
  743. .sp
  744. .if n \{\
  745. .RS 4
  746. .\}
  747. .nf
  748. working index HEAD target working index HEAD
  749. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  750. B C C D \-\-soft B C D
  751. \-\-mixed B D D
  752. \-\-hard D D D
  753. \-\-merge (disallowed)
  754. \-\-keep (disallowed)
  755. .fi
  756. .if n \{\
  757. .RE
  758. .\}
  759. .sp
  760. .if n \{\
  761. .RS 4
  762. .\}
  763. .nf
  764. working index HEAD target working index HEAD
  765. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  766. B C C C \-\-soft B C C
  767. \-\-mixed B C C
  768. \-\-hard C C C
  769. \-\-merge B C C
  770. \-\-keep B C C
  771. .fi
  772. .if n \{\
  773. .RE
  774. .\}
  775. .sp
  776. \fBreset\fR \fB\-\-merge\fR is meant to be used when resetting out of a conflicted merge\&. Any mergy operation guarantees that the working tree file that is involved in the merge does not have a local change with respect to the index before it starts, and that it writes the result out to the working tree\&. So if we see some difference between the index and the target and also between the index and the working tree, then it means that we are not resetting out from a state that a mergy operation left after failing with a conflict\&. That is why we disallow \fB\-\-merge\fR option in this case\&.
  777. .sp
  778. \fBreset\fR \fB\-\-keep\fR is meant to be used when removing some of the last commits in the current branch while keeping changes in the working tree\&. If there could be conflicts between the changes in the commit we want to remove and the changes in the working tree we want to keep, the reset is disallowed\&. That\(cqs why it is disallowed if there are both changes between the working tree and \fBHEAD\fR, and between \fBHEAD\fR and the target\&. To be safe, it is also disallowed when there are unmerged entries\&.
  779. .sp
  780. The following tables show what happens when there are unmerged entries:
  781. .sp
  782. .if n \{\
  783. .RS 4
  784. .\}
  785. .nf
  786. working index HEAD target working index HEAD
  787. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  788. X U A B \-\-soft (disallowed)
  789. \-\-mixed X B B
  790. \-\-hard B B B
  791. \-\-merge B B B
  792. \-\-keep (disallowed)
  793. .fi
  794. .if n \{\
  795. .RE
  796. .\}
  797. .sp
  798. .if n \{\
  799. .RS 4
  800. .\}
  801. .nf
  802. working index HEAD target working index HEAD
  803. \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
  804. X U A A \-\-soft (disallowed)
  805. \-\-mixed X A A
  806. \-\-hard A A A
  807. \-\-merge A A A
  808. \-\-keep (disallowed)
  809. .fi
  810. .if n \{\
  811. .RE
  812. .\}
  813. .sp
  814. \fBX\fR means any state and \fBU\fR means an unmerged index\&.
  815. .SH "GIT"
  816. .sp
  817. Part of the \fBgit\fR(1) suite