前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git 一些undo操作

git 一些undo操作

作者头像
ke1th
发布2019-08-14 11:43:43
5590
发布2019-08-14 11:43:43
举报

使用git的时候经常会出现,“啊!,刚才提交的代码有问题,需要undo一下了” 这种情况,为了应对这种问题。本文介绍 git 的一些 undo 操作

在使用 git 时,可以分为4个工作区域:

  • working area: 本机工作区
  • staging area:当执行 git add时候,文件就会到 staging area
  • local repo: 当执行 git commit 时候,文件就会 从 staging arealocal repo
  • remote repo: 当执行 git push 的时候,local repo 文件就会同步到 remote repo

UNDO:

  • working area:当在 working area写了个bug,undo的话就 backspace 就好了
  • staging area: 在 git add 的时候,突然发现多 add 了个文件,这时候 git checkout <file> 就可以了(此操作不会修改working area中的内容)
  • local repo: 如果想撤回上一次或者几次 commit 怎么办。
    • git reset HEAD~1 (默认为 --mixed) 。撤销git commit, git add 操作, 保留 working area的修改。
    • git reset --soft HEAD~1。撤销 git commit 操作,保留 working area的修改,git add 操作。
    • git reset --hard HEAD~1。撤销 git commit, git add ,working area的修改。
    • git reset HEAD~2。撤销两次提交
  • remote repo:当执行 git push 之后发现坏事了,怎么办
    • git revert commit-id。会删除本次同步的所有内容,并重新add ,commit, push
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年08月02日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档