您现在的位置是: 首页> 其他>git删除指定commit记录 所属分类:其他

git删除指定commit记录

初柒先生 2019-09-15 14:33 git 206人已围观

简介用git管理项目,有时候我们可能commit一些没用的记录,所以我们需要将其删除。

用git管理项目,有时候我们可能commit一些没用的记录,所以我们需要将其删除。

具体步骤如下:

1、查看提交记录:git log或者git log --oneline

2、选择要删除记录:复制最早提交的那条记录ID(commit-id)

下面的命令执行后会弹出编辑数据

git rebase -i (commit-id) 

编辑数据如下:

pick 5ae2d33 update
pick e834557 update2
pick b489f01 2019-09-15 修复cms模块首页程序人生图片
pick 969284b 2019-09-15 cms模块前台详情页url优化

# Rebase e3c510d..969284b onto e3c510d (4 commands)
#
# Commands:
# p, pick  = use commit
# r, reword  = use commit, but edit the commit message
# e, edit  = use commit, but stop for amending
# s, squash  = use commit, but meld into previous commit
# f, fixup  = like "squash", but discard this commit's log message
# x, exec  = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop  = remove commit
# l, label  = label current HEAD with a name
# t, reset  = reset HEAD to a label
# m, merge [-C  | -c ]  [# ]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c  to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

3、编辑上面弹出的文件文件,将要删除的commit-id前面的“pick”改为“drop ”,然后保存文件退出即可。

drop 5ae2d33 update
drop e834557 update2
pick b489f01 2019-09-15 修复cms模块首页程序人生图片
pick 969284b 2019-09-15 cms模块前台详情页url优化

4、查看是否删除成功:git log或者git log --oneline

查看后,我们会发现“update”和“update2”这两条记录不见了。

最后还需要将删除的记录更新到远程仓库,执行下面命令:

git push origin HEAD --force

注意:如果没有提交到远程仓库,那么我们删除的只是本地仓库,远程仓库还是没有变化。


很赞哦! (0)

初柒先生 2019-09-15 14:33 git 206人已围观

站点信息

  • 建站时间:2019-09-04
  • 网站名称:初柒先生
  • 主题模板《今夕何夕》
  • 文章统计:299条
  • 文章评论:490条
  • 统计数据百度统计
  • 微信公众号:初柒先生(chuqi_sir)
  • 微信扫二维码,关注我们吧!
搜索历史:
0.070698s