Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

git - Why do I have to stash / commit my changes before switching branches?

I find this to be annoying because I would like to quickly switch branches and do something and then switch back to what I was working on before. I realize I can stash and then retrieve stash, but then I have to type those lines every time :/

Is there any way to avoid having to do this?

I also find it annoying because I keep about 5 or 10 feature branches and it gets hard to manage which ones have a stash that needs to be retrieved and which ones are good to keep working on as they are.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One way to make this easier is to use something like Legit. One of the commands I like from Legit is git switch:

$ git switch <branch>
# Switches to branch. Stashes and restores unstaged changes.

Legit stores the stash with a description that follows a particular naming convention. That way, when you use git switch to return to the first branch, it can automatically unstash the changes saved for that branch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...