From d002ef4d9446b9fe4d0c397131edce58781df2f1 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Sat, 15 Aug 2009 13:48:31 +0200 Subject: Implement 'git reset --patch' This introduces a --patch mode for git-reset. The basic case is git reset --patch -- [files...] which acts as the opposite of 'git add --patch -- [files...]': it offers hunks for *un*staging. Advanced usage is git reset --patch -- [files...] which offers hunks from the diff between the index and for forward application to the index. (That is, the basic case is just = HEAD.) Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index abb25d1c00..469cf6dbac 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -10,6 +10,7 @@ SYNOPSIS [verse] 'git reset' [--mixed | --soft | --hard | --merge] [-q] [] 'git reset' [-q] [] [--] ... +'git reset' --patch [] [--] [...] DESCRIPTION ----------- @@ -23,8 +24,9 @@ the undo in the history. If you want to undo a commit other than the latest on a branch, linkgit:git-revert[1] is your friend. -The second form with 'paths' is used to revert selected paths in -the index from a given commit, without moving HEAD. +The second and third forms with 'paths' and/or --patch are used to +revert selected paths in the index from a given commit, without moving +HEAD. OPTIONS @@ -50,6 +52,15 @@ OPTIONS and updates the files that are different between the named commit and the current commit in the working tree. +-p:: +--patch:: + Interactively select hunks in the difference between the index + and (defaults to HEAD). The chosen hunks are applied + in reverse to the index. ++ +This means that `git reset -p` is the opposite of `git add -p` (see +linkgit:git-add[1]). + -q:: Be quiet, only report errors. -- cgit v1.2.3 From a75d7b54097ef0d0945cbe673a9940d6c561f95c Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 24 Oct 2009 11:31:32 +0300 Subject: Use 'fast-forward' all over the place It's a compound word. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 469cf6dbac..2d27e405a3 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -150,7 +150,7 @@ Automatic merge failed; fix conflicts and then commit the result. $ git reset --hard <2> $ git pull . topic/branch <3> Updating from 41223... to 13134... -Fast forward +Fast-forward $ git reset --hard ORIG_HEAD <4> ------------ + @@ -161,7 +161,7 @@ right now, so you decide to do that later. which is a synonym for "git reset --hard HEAD" clears the mess from the index file and the working tree. <3> Merge a topic branch into the current branch, which resulted -in a fast forward. +in a fast-forward. <4> 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 ORIG_HEAD, so resetting hard to it -- cgit v1.2.3 From 5d2dcc423ec689ff4a6bcb83b00d5b43657b0c88 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Wed, 2 Dec 2009 23:28:40 +0200 Subject: General --quiet improvements 'git reset' is missing --quiet, and 'git gc' is not using OPT__QUIET. Let's fix that. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 2d27e405a3..9df6de2e7d 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -62,6 +62,7 @@ This means that `git reset -p` is the opposite of `git add -p` (see linkgit:git-add[1]). -q:: +--quiet:: Be quiet, only report errors. :: -- cgit v1.2.3 From 4086010c7c83d907321ae1357569dfcc01710cb6 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Wed, 30 Dec 2009 06:54:45 +0100 Subject: Documentation: reset: add some tables to describe the different options This patch adds a DISCUSSION section that contains some tables to show how the different "git reset" options work depending on the states of the files in the working tree, the index, HEAD and the target commit. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 2d27e405a3..2198c8ebd6 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -67,6 +67,72 @@ linkgit:git-add[1]). :: Commit to make the current HEAD. If not given defaults to HEAD. +DISCUSSION +---------- + +The tables below show what happens when running: + +---------- +git reset --option target +---------- + +to reset the HEAD to another commit (`target`) with the different +reset options depending on the state of the files. + + working index HEAD target working index HEAD + ---------------------------------------------------- + A B C D --soft A B D + --mixed A D D + --hard D D D + --merge (disallowed) + + working index HEAD target working index HEAD + ---------------------------------------------------- + A B C C --soft A B C + --mixed A C C + --hard C C C + --merge (disallowed) + + working index HEAD target working index HEAD + ---------------------------------------------------- + B B C D --soft B B D + --mixed B D D + --hard D D D + --merge D D D + + working index HEAD target working index HEAD + ---------------------------------------------------- + B B C C --soft B B C + --mixed B C C + --hard C C C + --merge C C C + +In these tables, A, B, C and D are some different states of a +file. For example, the last line of the last table means that if a +file is in state B in the working tree and the index, and in a +different state C in HEAD and in the target, then "git reset +--merge target" will put the file in state C in the working tree, +in the index and in HEAD. + +The following tables show what happens when there are unmerged +entries: + + working index HEAD target working index HEAD + ---------------------------------------------------- + X U A B --soft (disallowed) + --mixed X B B + --hard B B B + --merge (disallowed) + + working index HEAD target working index HEAD + ---------------------------------------------------- + X U A A --soft (disallowed) + --mixed X A A + --hard A A A + --merge (disallowed) + +X means any state and U means an unmerged index. + Examples -------- -- cgit v1.2.3 From d0f379c2dcf7198d373b3c64444019bed2e24336 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 30 Dec 2009 06:54:47 +0100 Subject: reset: use "unpack_trees()" directly instead of "git read-tree" This patch makes "reset_index_file()" call "unpack_trees()" directly instead of forking and execing "git read-tree". So the code is more efficient. And it's also easier to see which unpack_tree() options will be used, as we don't need to follow "git read-tree"'s command line parsing which is quite complex. As Daniel Barkalow found, there is a difference between this new version and the old one. The old version gives an error for "git reset --merge" with unmerged entries, and the new version does not when we reset the entries to some states that differ from HEAD. Instead, it resets the index entry and succeeds, while leaving the conflict markers in the corresponding file in the work tree (which will be corrected by the next patch). The code comes from the sequencer GSoC project: git://repo.or.cz/git/sbeyer.git (at commit 5a78908b70ceb5a4ea9fd4b82f07ceba1f019079) Mentored-by: Daniel Barkalow Mentored-by: Christian Couder Signed-off-by: Stephan Beyer Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 2198c8ebd6..cf2433d52c 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -122,7 +122,7 @@ entries: X U A B --soft (disallowed) --mixed X B B --hard B B B - --merge (disallowed) + --merge X B B working index HEAD target working index HEAD ---------------------------------------------------- -- cgit v1.2.3 From e11d7b5969704cd5ce39d053414d905bb203886b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 31 Dec 2009 23:04:04 -0800 Subject: "reset --merge": fix unmerged case Commit 9e8ecea (Add 'merge' mode to 'git reset', 2008-12-01) disallowed "git reset --merge" when there was unmerged entries. But it wished if unmerged entries were reset as if --hard (instead of --merge) has been used. This makes sense because all "mergy" operations makes sure that any path involved in the merge does not have local modifications before starting, so resetting such a path away won't lose any information. The previous commit changed the behavior of --merge to accept resetting unmerged entries if they are reset to a different state than HEAD, but it did not reset the changes in the work tree, leaving the conflict markers in the resulting file in the work tree. Fix it by doing three things: - Update the documentation to match the wish of original "reset --merge" better, namely, "An unmerged entry is a sign that the path didn't have any local modification and can be safely resetted to whatever the new HEAD records"; - Update read_index_unmerged(), which reads the index file into the cache while dropping any higher-stage entries down to stage #0, not to copy the object name from the higher stage entry. The code used to take the object name from the a stage entry ("base" if you happened to have stage #1, or "ours" if both sides added, etc.), which essentially meant that you are getting random results depending on what the merge did. The _only_ reason we want to keep a previously unmerged entry in the index at stage #0 is so that we don't forget the fact that we have corresponding file in the work tree in order to be able to remove it when the tree we are resetting to does not have the path. In order to differentiate such an entry from ordinary cache entry, the cache entry added by read_index_unmerged() is marked as CE_CONFLICTED. - Update merged_entry() and deleted_entry() so that they pay attention to cache entries marked as CE_CONFLICTED. They are previously unmerged entries, and the files in the work tree that correspond to them are resetted away by oneway_merge() to the version from the tree we are resetting to. Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index cf2433d52c..dc73dca736 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -122,14 +122,14 @@ entries: X U A B --soft (disallowed) --mixed X B B --hard B B B - --merge X B B + --merge B B B working index HEAD target working index HEAD ---------------------------------------------------- X U A A --soft (disallowed) --mixed X A A --hard A A A - --merge (disallowed) + --merge A A A X means any state and U means an unmerged index. -- cgit v1.2.3 From 397d596f84209d0e9d17621ce56b5432bc98d368 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Tue, 5 Jan 2010 06:58:30 +0100 Subject: Documentation: reset: add some missing tables and while at it also explain why --merge option is disallowed in some cases. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index dc73dca736..c137183574 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -79,6 +79,13 @@ git reset --option target to reset the HEAD to another commit (`target`) with the different reset options depending on the state of the files. +In these tables, A, B, C and D are some different states of a +file. For example, the first line of the first table means that if a +file is in state A in the working tree, in state B in the index, in +state C in HEAD and in state D in the target, then "git reset --soft +target" will put the file in state A in the working tree, in state B +in the index and in state D in HEAD. + working index HEAD target working index HEAD ---------------------------------------------------- A B C D --soft A B D @@ -107,12 +114,28 @@ reset options depending on the state of the files. --hard C C C --merge C C C -In these tables, A, B, C and D are some different states of a -file. For example, the last line of the last table means that if a -file is in state B in the working tree and the index, and in a -different state C in HEAD and in the target, then "git reset ---merge target" will put the file in state C in the working tree, -in the index and in HEAD. + working index HEAD target working index HEAD + ---------------------------------------------------- + B C C D --soft B C D + --mixed B D D + --hard D D D + --merge (disallowed) + + working index HEAD target working index HEAD + ---------------------------------------------------- + B C C C --soft B C C + --mixed B C C + --hard C C C + --merge B C C + +"reset --merge" is meant to be used when resetting out of a conflicted +merge. Any mergy operation guarantees that the work tree file that is +involved in the merge does not have local change wrt the index before +it starts, and that it writes the result out to the work tree. So if +we see some difference between the index and the target and also +between the index and the work 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 --merge option in this case. The following tables show what happens when there are unmerged entries: -- cgit v1.2.3 From 0b444cdb19bcfcc7f59b7b00783cbfbbc5ddcf63 Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Sun, 10 Jan 2010 00:33:00 +0100 Subject: Documentation: spell 'git cmd' without dash throughout The documentation was quite inconsistent when spelling 'git cmd' if it only refers to the program, not to some specific invocation syntax: both 'git-cmd' and 'git cmd' spellings exist. The current trend goes towards dashless forms, and there is precedent in 647ac70 (git-svn.txt: stop using dash-form of commands., 2009-07-07) to actively eliminate the dashed variants. Replace 'git-cmd' with 'git cmd' throughout, except where git-shell, git-cvsserver, git-upload-pack, git-receive-pack, and git-upload-archive are concerned, because those really live in the $PATH. --- Documentation/git-reset.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 2d27e405a3..17c119d874 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -39,7 +39,7 @@ OPTIONS --soft:: Does not touch the index file nor the working tree at all, but requires them to be in a good order. This leaves all your changed - files "Changes to be committed", as 'git-status' would + files "Changes to be committed", as 'git status' would put it. --hard:: -- cgit v1.2.3 From 7349df1142a8dba579c015b51805cc290fcb4e6e Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Fri, 5 Mar 2010 21:25:36 +0100 Subject: Documentation: reset: describe new "--keep" option and give an example to show how it can be used. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 49 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 168db08627..1e9ae0ae9f 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -8,7 +8,7 @@ git-reset - Reset current HEAD to the specified state SYNOPSIS -------- [verse] -'git reset' [--mixed | --soft | --hard | --merge] [-q] [] +'git reset' [--mixed | --soft | --hard | --merge | --keep] [-q] [] 'git reset' [-q] [] [--] ... 'git reset' --patch [] [--] [...] @@ -52,6 +52,11 @@ OPTIONS and updates the files that are different between the named commit and the current commit in the working tree. +--keep:: + Resets the index to match the tree recorded by the named commit, + but keep changes in the working tree. Aborts if the reset would + change files that are already modified in the working tree. + -p:: --patch:: Interactively select hunks in the difference between the index @@ -93,6 +98,7 @@ in the index and in state D in HEAD. --mixed A D D --hard D D D --merge (disallowed) + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -100,6 +106,7 @@ in the index and in state D in HEAD. --mixed A C C --hard C C C --merge (disallowed) + --keep A C C working index HEAD target working index HEAD ---------------------------------------------------- @@ -107,6 +114,7 @@ in the index and in state D in HEAD. --mixed B D D --hard D D D --merge D D D + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -114,6 +122,7 @@ in the index and in state D in HEAD. --mixed B C C --hard C C C --merge C C C + --keep B C C working index HEAD target working index HEAD ---------------------------------------------------- @@ -121,6 +130,7 @@ in the index and in state D in HEAD. --mixed B D D --hard D D D --merge (disallowed) + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -128,6 +138,7 @@ in the index and in state D in HEAD. --mixed B C C --hard C C C --merge B C C + --keep B C C "reset --merge" is meant to be used when resetting out of a conflicted merge. Any mergy operation guarantees that the work tree file that is @@ -138,6 +149,14 @@ between the index and the work 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 --merge option in this case. +"reset --keep" 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's why it is disallowed if there are both +changes between the working tree and HEAD, and between HEAD and the +target. + The following tables show what happens when there are unmerged entries: @@ -147,6 +166,7 @@ entries: --mixed X B B --hard B B B --merge B B B + --keep (disallowed) working index HEAD target working index HEAD ---------------------------------------------------- @@ -154,6 +174,7 @@ entries: --mixed X A A --hard A A A --merge A A A + --keep X A A X means any state and U means an unmerged index. @@ -325,6 +346,32 @@ $ git add frotz.c <3> <2> This commits all other changes in the index. <3> Adds the file to the index again. +Keep changes in working tree while discarding some previous commits:: ++ +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 commited previously. You can start a new branch and +reset it while keeping the changes in your work tree. ++ +------------ +$ git tag start +$ git checkout -b branch1 +$ edit +$ git commit ... <1> +$ edit +$ git checkout -b branch2 <2> +$ git reset --keep start <3> +------------ ++ +<1> This commits your first edits in branch1. +<2> 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 branch2 (i.e. "git checkout -b branch2 start"), but nobody is + perfect. +<3> But you can use "reset --keep" to remove the unwanted commit after + you switched to "branch2". + Author ------ Written by Junio C Hamano and Linus Torvalds -- cgit v1.2.3 From 812d2a3d61b1bbb1931aff2ed6d2a17e939f5bf2 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Tue, 19 Jan 2010 05:26:01 +0100 Subject: reset: disallow using --keep when there are unmerged entries The use case for --keep option is to remove previous commits unrelated to the current changes in the working tree. So in this use case we are not supposed to have unmerged entries. This is why it seems safer to just disallow using --keep when there are unmerged entries. And this patch changes the error message when --keep was disallowed and there were some unmerged entries from: error: Entry 'file1' would be overwritten by merge. Cannot merge. fatal: Could not reset index file to revision 'HEAD^'. to: fatal: Cannot do a keep reset in the middle of a merge. which is nicer. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 1e9ae0ae9f..58d9b4c062 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -155,7 +155,8 @@ 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's why it is disallowed if there are both changes between the working tree and HEAD, and between HEAD and the -target. +target. To be safe, it is also disallowed when there are unmerged +entries. The following tables show what happens when there are unmerged entries: @@ -174,7 +175,7 @@ entries: --mixed X A A --hard A A A --merge A A A - --keep X A A + --keep (disallowed) X means any state and U means an unmerged index. -- cgit v1.2.3 From eaf436c09c09a28804697c89f3ff9a7e1ad2361c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 9 Mar 2010 02:51:16 +0100 Subject: Documentation: improve description of "git reset --keep" Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Documentation/git-reset.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Documentation/git-reset.txt') diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index 58d9b4c062..645f0c1748 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -53,9 +53,12 @@ OPTIONS and the current commit in the working tree. --keep:: - Resets the index to match the tree recorded by the named commit, - but keep changes in the working tree. Aborts if the reset would - change files that are already modified in the working tree. + Reset the index to the given commit, keeping local changes in + the working tree since the current commit, while updating + working tree files without local changes to what appears in + the given commit. If a file that is different between the + current commit and the given commit has local changes, reset + is aborted. -p:: --patch:: -- cgit v1.2.3