Search code examples
gitvisual-studiogithubvisual-studio-2019git-cherry-pick

Cherry Pick Problem in Visual Studio 2019


I just ran into a problem caused by cherry picking within VS2019 which caused me to have to blow away and recreate both my local and github repositories. No big deal as the code was reasonably stable and I'm not co-developing it with anyone.

But I'd like to know what I did wrong so I don't do it again.

I had two branches in the repository, master and dev. I had made one particular change in dev which I wanted to propagate back to master. So, following some directions I found online, I made master the active branch, right-clicked the dev branch and selected Cherry Pick. Thinking that I would be presented with a history list of commits on dev from which I would pick the one I wanted (which was the most recent one).

Only...nothing appeared to happen. Nothing showed up under Changes.

So, thinking I'd messed up somehow, I followed a different set of directions and brought up dev's history while still leaving master as the active branch. From within the history I right-clicked the commit I wanted and selected Cherry Pick.

Still nothing seemed to happen. But I noticed the code change (it was in one place in one file) >>had<< appeared in the master (active) branch.

But when I tried to sync the local repository to github I was told there was an error involving some inconsistency between github and the local repsitory (apologies, I didn't think to copy the error messages down). Things spiraled out of control from there (I think I tried pulling changes from github to cure the inconsistency and then ended up with another error about the local repository head being behind the github repository head or something like that).

If this poor description provides enough clues as to how I messed up, and what I should've done, I'd appreciate the info.


Solution

  • Using command-line in this case would have been safer, with git cherry-pick.

    A git reflog would also have helped recover the situation, but allowing you to reset to an older commit (before those operations)

    As illustrated here (with Visual Studio 2019), look for conflict resolution when cherry-picking, or it would be "stuck" in an intermediate state that Visual Studio does not identify well.