github / VisualStudio

GitHub Extension for Visual Studio
https://visualstudio.github.com
MIT License
2.38k stars 1.2k forks source link

Moves all your changes to your newly created branch, after wrongfully making changes to master #2513

Open khabubu opened 4 years ago

khabubu commented 4 years ago

Is your feature request related to a problem? Please describe. I'm always frustrated when I make changes to master branch and what to switch those changes to a new branch or an existing branch.

Describe the solution you'd like I would like to be able to switch to a new or existing branch and move those changes to that brunch through a user interface where I can switch to branch with changes.

Describe alternatives you've considered The current alternative is to open the command prompt and enter the following command

𝚐𝚒𝚝 𝚜𝚠𝚒𝚝𝚌𝚑 -𝚌 "𝚢𝚘𝚞𝚛_𝚗𝚎𝚠_𝚋𝚛𝚊𝚗𝚌𝚑"

Or if the branch already exists

𝚐𝚒𝚝 𝚜𝚠𝚒𝚝𝚌𝚑 "𝚢𝚘𝚞𝚛_existing_𝚋𝚛𝚊𝚗𝚌𝚑"
jcansdale commented 4 years ago

@daschult,

I think this is more of a new Get Experience feature request. Do you know if there's an easy way to move your changes to a different branch using the new UI? This is certainly a frustration I've had when using Git in the past!

ghost commented 4 years ago

Hi Khabubu,

I'm just trying to understand your scenario a little bit better. You situation looks like this, right?

  1. Accidentally make commits to master branch.
  2. You create a new branch off of master.
  3. You switch to new branch.

I think you can accomplish this pretty simply by just "git checkout -b " from master. If you want to reset master to before the accidental commit, then you can run "git reset --hard ". You can also do all of this using Team Explorer or the Git tool window in Visual Studio. Before I go into those instructions, though, do you feel like I'm understanding your scenario?

Thanks!

khabubu commented 4 years ago

Hi Dan

You have partially understood my scenario. In my scenarioI have not yet commited to master branch but I have changed a file while on the master branch and I don't want to lose the changes. Now your alternative is valid if I had commited to the master brunch hence the you have suggested to use "git checkout -b", however I want to use the new UI to switch between the local master branch to another local branch withou losing those changes.

Hence I provided the current alternative I use which is using the command line and execute the following command "git switch dev".

jcansdale commented 4 years ago

@daschult,

The situation I would often get into was this:

  1. I'm reviewing someone's pull request on a branch
  2. I notice and fix an unrelated bug, forgetting to create a new branch
  3. I try to change to the default branch, but can't because the file I touched has changed
  4. At this point, I need to Stash, change to the default branch, pop my Stash (and pray there are no merge conflicts)

I wish there was a streamlined way to do 4 ☝️

Reading up on the git switch command that @khabubu mentioned (see here), I think this might be the command I'm looking for!

image

Maybe this is simply a case of the new Git experience using the new git switch command instead of the legacy git checkout command. I always found checkout's insistence on a clean working tree to be a burden (particularly when working with submodules).

In summary, I think it's a great idea to consider using git switch either as the default or at least an option!