How to recover from git “added by us” conflict after applying stash after renaming

后端 未结 2 702
感动是毒
感动是毒 2021-01-23 13:10

I don\'t recall how my git local repo got into this state, but here is the situation:

My status on the command line says "nothing to commit, working tree clean"

相关标签:
2条回答
  • 2021-01-23 13:25

    If you are interested in the content of datastore/static/js/app/main.js, it looks like the stash has stored the action "delete this file". The content you wish to recover is maybe stored in the commit before the stash.

    To make sense of the gibberish I wrote above :

    From a terminal, run :

    git log --oneline --graph stash@{0}
    

    You will see that your stash is actually a commit (it just isn't stored in one of your branches), and that it has a parent commit (which was the state of your work at some point).

    You can view the full content of the file in the stash :

    git show stash@{0}:datastore/static/js/app/main.js
    

    and the full content of the file in the "parent commit" :

    git show <parentsha1>:datastore/static/js/app/main.js
    

    If my guess is correct, the first "git show" will be empty.

    Anyway, you can get the content you wish :

    git checkout <the correct ref> -- datastore/static/js/app/main.js
    

    and then use it however you want.

    0 讨论(0)
  • 2021-01-23 13:37

    You might come back to the version where you stashed from, stash pop, rename the file, then stash save again, then junp back to the revision you are currently working on and stash pop. Then rename should not be an issue

    0 讨论(0)
提交回复
热议问题