![]() What the blog post's author did was: git reset -hard origin/mallard-documentation See " How do I fix merge conflicts in Git?" What you did was to fix the merge conflict (editing the right file, and committing it): You can find a similar situation 4 days ago at the time of writing this answer (March 13th, 2012) with this post: " ‘Pull is not possible because you have unmerged files’": git stash pop ![]() You can then git stash the rest if you want. If you do not want to commit, just git add yourFile is enough. ![]() Solution: in this case, simply add and commit your local file.Īctually, just git add - yourFile, or (if you don't want those changes) git reset - yourFile (to unstage it) is enough to get past the error message. That is where git status would mention that file as being " both modified" In this case, you'll get the usual unmerged conflicts that you can resolve with git merge/git mergetool/etc.The actual issue was an unresolved merge conflict from the merge, NOT that the stash would cause a merge conflict. In some cases, the working tree changes may depend on the index changes, so when you stash the index changes, the working tree changes have a conflict. Now the stash contains a new entry that only contains the changes you had staged, and your working tree still contains any unstaged changes. You can save the above script as git-stash-index somewhere on your path, and can then invoke it as git stash-index # # However, if there are conflicts, then we don't want to reset the files # any previously unstaged changes remain unstaged # If there are no conflicts, it's safe to reset, so that # Now cherry-pick the working tree changes. # This cherry-pick is guaranteed to succeed # Cherry-pick the index changes back to the index, and stash. # get back to a clean state with no changes, staged or otherwise WORKINGCOMMIT=`echo "" | git commit-tree $WORKINGTREE -p $INDEXCOMMIT` # create a child commit with the changes in the working tree INDEXCOMMIT=`echo "" | git commit-tree $INDEXTREE -p HEAD` # create a commit with only the stuff in staging Unfortunately, git doesn't offer a git stash -only-index or similar, so I whipped up a script to do this. That is, to stage some changes, and then stash only those staged changes. I often find it more intuitive to do the inverse of approach. Update () - I've rewritten the script a bit, to better handle the case of conflicts, which should now be presented as unmerged conflicts rather than. git checkout - afile # reset the file to the HEAD content, before any local modificationsĪt the end of that rather cumbersome process, you will have only one or several files stashed.git stash pop # re-apply all your files modifications.git stash # this time, only the files you want are stashed.(Actually, eleotlecram proposes an interesting alternative) If -patch doesn't work, a manual process might:įor one or several files, an intermediate solution would be to: However that will save the full index (which may not be what you want since it might include other files already indexed), and a partial worktree (which could look like the one you want to stash). The selected changes are then rolled back from your worktree. The stash entry is constructed such that its index state is the same as the index state of your repository, and its worktree contains only the changes you selected interactively. With -patch, you can interactively select hunks from in the diff between HEAD and the working tree to be stashed. Yet, git stash save -patch could allows you to achieve the partial stashing you are after: (Original answer June 2010: manual stash) In order to get to the original state - which is a clear staging area and with only some select un-staged modifications, one could softly reset the index to get (without committing anything like you - bukzor - did). You should " git reset -soft" after such a stash to get your clear staging back: Go see and upvote his answer, which should be the official one (instead of mine).Ībout that option, chhh points out an alternative workflow in the comments: This (the stash -patch original solution) is nice, but often I've modified a lot of files so using patch is annoyingīukzor's answer (upvoted, November 2011) suggests a more practical solution, based on The original answer (below, June 2010) was about manually selecting what you want to stash. The test case for this feature shows a few more options off: test_expect_success 'stash with multiple pathspec arguments' ' Simplified example: git stash push path/to/file See " Stash changes to specific files" for more. When pathspec is given to ' git stash push', the new stash records the modified states only for the files that match the pathspec ![]() Since Git 2.13 (Q2 2017), you can stash individual files, with git stash push: git stash push ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |