git rebase 的使用 (用于撤销某次commit)
Q:
I wrote the wrong thing in a commit message. Alternatively, I've forgotten to include some files.
How can I change the commit message/files? The commit has not been pushed yet.
A:
有两种方法:
1.
Amending the most recent commit message
git commit --amend
will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with:
git commit --amend -m "New commit message"
…however, this can make multi-line commit messages or small corrections more cumbersome to enter.
Make sure you don't have any working copy changes staged before doing this or they will get committed too. (Unstaged changes will not get committed.)
Changing the message of a commit that you've already pushed to your remote branch
If you've already pushed your commit up to your remote branch, then you'll need to force push the commit with:
git push <remote> <branch> --force
# Or
git push <remote> <branch> -f
Warning: force-pushing will overwrite the remote branch with the state of your local one. If there are commits on the remote branch that you don't have in your local branch, you willlose those commits.
Warning: be cautious about amending commits that you have already shared with other people. Amending commits essentially rewrites them to have different SHA IDs, which poses a problem if other people have copies of the old commit that you've rewritten. Anyone who has a copy of the old commit will need to synchronize their work with your newly re-written commit, which can sometimes be difficult, so make sure you coordinate with others when attempting to rewrite shared commit history, or just avoid rewriting shared commits altogether.
2.
Use interactive rebase
Another option is to use interactive rebase.
This allows you to edit any message you want to update even if it's not the latest message.
In order to do a git squash, follow these steps:
// X is the number of commits to the last commit you want to be able to edit
git rebase -i HEAD~X
Once you squash your commits - choose the e/r for editing the message

Important note about Interactive rebase
When you use the git rebase -i HEAD~X there can be more than X commits. Git will "collect" all the commits in the last X commits and if there was a merge somewhere in between that range you will see all the commits as well so the outcome will be X+.
Good tip:
If you have to do it for more than a single branch and you might face conflicts when amending the content, set up git rerere and let git resolve those conflicts automatically for you.
git rebase 的使用 (用于撤销某次commit)的更多相关文章
- git rebase简介(基本篇)
原文: http://gitbook.liuhui998.com/4_2.html 一.基本 git rebase用于把一个分支的修改合并到当前分支. 假设你现在基于远程分支"origin& ...
- Git git rebase 使用
原文:http://gitbook.liuhui998.com/4_2.html 一.基本 git rebase用于把一个分支的修改合并到当前分支. 假设你现在基于远程分支"origin ...
- git rebase 使用
git rebase 不会取回代码 要用git fetch先取回, git rebase 是合并代码. (1)首先用git fetch返回服务器上的代码 (2)首先用git rebase origin ...
- git<git rebase 修改以前提交过的内容>
git rebase 使用总结: 使用git rebase 修改以前已经提交的内容 比如要修改之前的commit的 hashcode为:187f869c9d54c9297d6b0b1b4ff47d ...
- 关于git rebase的相关讲解
http://gitbook.liuhui998.com/4_2.html 一.基本 git rebase用于把一个分支的修改合并到当前分支. 假设你现在基于远程分支"origin" ...
- git rebase 和 git merge 总结
git merge 和 git rebase 都是用于合并分支,但二者是存在区别的. 在使用时,记住以下两点: 当你从 remote 去 pull 的时候,永远使用 rebase(除了一个例外) 当你 ...
- 【转】git rebase简介(基本篇)
原文网址:http://blog.csdn.net/hudashi/article/details/7664631/ 原文: http://gitbook.liuhui998.com/4_2.html ...
- git 必看,各种撤销操作
场景概念说明 首先说明一个概念, git是一个分布式的版本控制工具,分布式即 git 管理的项目是有多个大致平等的仓库的.通过一个例子来说明这个东西. 举一个最简单的使用场景: 你在github 建立 ...
- (转)git rebase 命令
转自:http://blog.csdn.net/hudashi/article/details/7664631/ 原文: http://gitbook.liuhui998.com/4_2.html 一 ...
随机推荐
- caffe中lenet_solver.prototxt配置文件注解
caffe框架自带的例子mnist里有一个lenet_solver.prototxt文件,这个文件是具体的训练网络的引入文件,定义了CNN网络架构之外的一些基础参数,如总的迭代次数.测试间隔.基础学习 ...
- HTML5与CSS3权威指南之CSS3学习记录
title: HTML5与CSS3权威指南之CSS3学习记录 toc: true date: 2018-10-14 00:06:09 学习资料--<HTML5与CSS3权威指南>(第3版) ...
- 内部div自动扩张剩余宽度
<div id="container"> <div id="left">左边</div> <div id=" ...
- Linux部署之批量自动安装系统之测试篇
1. 客户端从网络启动如下 2. 复制vesamenu.c32文件可解决上面的问题 3. 客户端再次启动 4. 选择第一个进 ...
- ActiveMQ学习笔记(12)----ActiveMQ的集群
1. Queue consumer cluster ActiveMQ支持Consumer对消息的高可靠性的负载均衡消费,如果一个Consumer死掉,该消息会转发到其他的Consumer消费的Queu ...
- 关于目标检测 Object detection
NO1.目标检测 (分类+定位) 目标检测(Object Detection)是图像分类的延伸,除了分类任务,还要给定多个检测目标的坐标位置. NO2.目标检测的发展 R-CNN是最早基于C ...
- java中的json
josn: 一种数据传输格式,与开发语言无关,轻量级 一开始是javaScript的,但是后面比较流传,几乎所有语言都有相应的使用API 数据结构: Object---对象 使用花括号{}包含的键值对 ...
- python3 之 Ellipsis
在翻django 代码的时候无意中看到的, 主要还是在注解时候使用 官方参考:https://docs.python.org/3/library/constants.html#Ellipsis 注意: ...
- axios的坑
1.axios默认发送application/json 格式 https://www.cnblogs.com/qdcnbj/p/8143155.html 资料: https://www.npmjs.c ...
- (2016北京集训十四)【xsy1556】股神小D - LCT
题解: 题解居然是LCT……受教了 把所有区间按照端点排序,动态维护目前有重叠的区间,用LCT维护即可. 代码: #include<algorithm> #include<iostr ...