`git stash` during a merge conflict

前端 未结 5 933
猫巷女王i
猫巷女王i 2021-02-02 08:46

We\'ve done something bad.

We ran git stash save during a merge conflict, and now we can\'t restore our work.

Things we\'ve tried:

g         


        
5条回答
  •  孤独总比滥情好
    2021-02-02 09:04

    Given your last comment : you can use

    git stash megre --no-commit 
    

    to put the index in a "merge" state without committing the changes

    then modify it with what you want :

    if you have already worked out your merge in the stash :

    git reset #to remove the "conflicts" flags
    git checkout  -- ./ #to revert everything to the previous working state,
    git stash apply   #apply your changes
    

    and once everything is in the desired state, git commit


    About bukzor's comment : there is actually a big difference between git checkout and git checkout -- .

    From the reference on git checkout :

    • git checkout : This form switches branches by updating the index, working tree, and HEAD to reflect the specified branch or commit.

    • git checkout [-p|--patch] -- : When or --patch are given, git checkout does not switch branches. It updates the named paths in the working tree from the index file or from a named (most often a commit).

    git checkout would indeed discard the merge informations.

    git checkout -- ./ (note the extra -- ./), on the other hand, will keep the merge information, and revert every tracked file to its state in .

提交回复
热议问题