git 解决ahead behind分叉以及删除远端commit

本文介绍了如何使用Git进行一些高级操作,例如撤销提交、还原工作目录的状态以及如何处理分支之间的ahead/behind问题。还提供了如何删除本地和远程提交的具体步骤。
  1. 解决ahead / behind

先reset到ahead,然后退回到分叉,再checkout 远端的behind

如果要删除本地的commit, 先到本地的最前端, 然后再用下面的命令

If you want to fix up your latest commit, you can undo the commit, and
unstage the files in it, by doing:

git reset HEAD~1 This will return your repository to its state before
the git add commands that staged the files. Your changes will be in
your working directory. HEAD~1 refers to the commit below the current
tip of the branch.

If you want to uncommit N commits, but keep the code changes in your
working directory:

git reset HEAD~N If you want to get rid of your latest commit, and do
not want to keep the code changes, you can do a “hard” reset.

git reset –hard HEAD~1 Likewise, if you want to discard the last N
commits, and do not want to keep the code changes:

git reset –hard HEAD~N

2.删除远端commit

先退回到正确的local commit然后
git push –force

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值