切换到新提交的分支而不影响 master 分支的代码

Switch to newly committed branch without affecting code of master branch

所以我有我的 git 存储库,我在其中对主分支 进行了更改,但未提交

现在在 repo 上有一个 new 分支。

我想提取 new 分支代码,但我不希望它影响我的 master 分支的代码,因为 master 分支的代码未提交。

请指导..

看来您应该将您的更改存储在 master 和 pull 上并执行您想做的任何事情,然后最后取消存储您的更改。

git stash
git pull # Or whatever else you want to do
# Now back on master branch
git stash pop

这将存储您的本地更改并还原您的 HEAD。然后您可以稍后应用这些商店更改!

我是这样做的。

git stash #to have the track of uncommitted code
git pull #to get the latest code and branch
git checkout new #to switch the new branch.

现在如果我想用我未提交的旧代码切换到 master 分支,

git checkout master
git stash pop

谢谢大家