reset -soft to combine several sequential commits into a new one.Īnd more importantly, are there any other uses for reset -soft apart from amending a commit?.commit -amend to add/rm files from the very last commit or to change its message.Short answers to your questionsĪre these two commands really the same ( reset -soft vs commit -amend)?Īny reason to use one or the other in practical terms? Now all your changes are preserved and ready to be committed as one. So, undo the last 3 (or whatever) commits (without affecting the index nor working directory). Use Case - Combine a series of local commits You would get an " unknown option" error. * jc/parse-options-reset: reset: reject -no-(mixed|soft|hard|merge|keep) option (Merged by Junio C Hamano - gitster - in commit e672bc4, ) e672bc4f76:Merge branch 'jc/parse-options-reset'Ĭommand line parser fix. See commit 3821eb6 () by Junio C Hamano ( gitster). Note that -no-soft does not make sense, and Git 2.42 (Q3 2023) tells you so now. you are not satisfied with all the commits that took you to get there:.you are satisfied with what you end up with (in terms of working tree and index).git/MERGE_HEADĮcho $(git rev-parse projectB/master) >. Git reset -soft we can resume Tomas's solution: # Pretend that we just did an octopus merge with three heads:Įcho $(git rev-parse projectA/master) >. my working tree and index are fine, but without having to record those two commits? # Move the HEAD, and just the HEAD, two commits back! How do I redo those two merges, which have worked, i.e. Here the author used a reset -hard, and then read-tree to restore what the first two merges had done to the working tree and index, but that is where reset -soft can help: # Merge projectB with the subtree strategy: So this is what I do: # Merge projectA with the default strategy: The tricky part here is that this is an octopus merge (three heads), but projectB needs to be merged with the subtree strategy. Instead, I create a single merge commit which combines projectA, projectB and my local commits. When I decide to update both projects, I don't simply pull from projectA and projectB as that would create two commits for what should be an atomic update of the whole project. ProjectA is regularly updated, projectB has a new version every couple days or weeks and usually depends on a particular version of projectA. I'm also maintaining a few local commits. I have a superproject, let's call it projectA, and a subproject, projectB, that I merged into a subdirectory of projectA. But I wanted to combine the two in order to get a clean history in which the whole repository is atomically updated to a new version. The problem is that you can choose only one strategy. The normal strategy can merge only two branches and if you try to merge more than that, git automatically falls back to the octopus strategy. The octopus merge strategy can be used to merge three or more branches.The subtree merge strategy can be used if you want to merge one project into a subdirectory of another project, and the subsequently keep the subproject up to date.Tomas "wereHamster" Carnecky explains in his "Subtree Octopus merge" article: it can actually move HEAD to any commit (as commit -amend is only about not moving HEAD, while allowing to redo the current commit)Īll into one (octopus, since there are more than two branches merged) commit merge.When employed with -soft, moves HEAD, most often updating the branch ref, and only the HEAD. Question: what about the working tree and index? Git reset is all about moving HEAD, and generally the branch ref.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |