git代码写错分支了怎么办

tangqian 1年前 ⋅ 95 阅读

git代码写错分支了怎么办

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

<!--more-->

还没有提交代码

  1.  
    #第一步,将修改的代码暂存到stash
  2.  
    git stash
  3.  
     
  4.  
    #第二步,切换到正确的分支
  5.  
    git checkout targetbranch
  6.  
     
  7.  
    #第三步,从stash中取出暂存的代码修改。
  8.  
    git stash pop

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

  1.  
    git add .
  2.  
    git commit -m xxx

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

已经提交了

撤回即可

git reset HEAD^

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

已经push了

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

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


全部评论: 0

    我有话说: