git代码写错分支了怎么办

git代码写错分支了怎么办

git 还是很容易解决的。几行命令即可

<!--more-->

还没有提交代码

#第一步,将修改的代码暂存到stash
git stash

#第二步,切换到正确的分支
git checkout targetbranch 

#第三步,从stash中取出暂存的代码修改。
git stash pop

3行命令就可以切换到正确的分支,并把已经写好但未提交的代码放到正确的分支下了。
继续提交的话就是

git add .
git commit -m xxx

参考来源:https://www.cnblogs.com/crayfish/p/5719475.html

已经提交了

撤回即可

git reset HEAD^

然后继续执行 没提交时的操作

已经push了

同已经提交了的步骤。 先撤回,然后再push下撤回后的。不过会有记录

参考 https://gorden5566.com/post/1010.html

转载于:https://my.oschina.net/northerSong/blog/2218772