博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[GIT]
阅读量:5944 次
发布时间:2019-06-19

本文共 2513 字,大约阅读时间需要 8 分钟。

reference : 

Who is not tired of committing a "Remove pdb" or a "Fix a typo" few minutes or hours after committing a clean feature ? A few time ago, I discovered two useful options in GIT that work together : git commit --fixup andgit rebase --autosquash. With these, you can easily merge little fixes with the original feature and keep your branch clean.

Preferably, you won't use it in a stable or master branch, because rebase rewrites history and can create a big mess, mainly if project counts several developers. It rather can be convenient to clean a development branch before merging it in master.

--fixup & --autosquash

  • git commit --fixup <commit> automatically marks your commit as a fix of a previous commit
  • git rebase -i --autosquash automatically organize merging of these fixup commits and associated normal commits

Example

Take a git repos with a branch dev. You intend to commit features A and B:

$ (dev) git add featureA$ (dev) git commit -m "Feature A is done" [dev fb2f677] Feature A is done $ (dev) git add featureB $ (dev) git commit -m "Feature B is done" [dev 733e2ff] Feature B is done

Your work is in progress and you find minor mistakes in Feature A : it's time to use --fixup option !

$ (dev) git add featureA                # you've removed a pdb : shameful commit$ (dev) git commit --fixup fb2f677 [dev c5069d5] fixup! Feature A is done

Here, you see that GIT automatically retrieved featureA commit message prefixed by fixup!.

All work is done, let's see the log:

$ (dev) git log --onelinec5069d5 fixup! Feature A is done733e2ff Feature B is donefb2f677 Feature A is done ac5db87 Previous commit

Now, you want to clean your branch before merging it : it's time to use --autosquash option !

$ (dev) git rebase -i --autosquash ac5db87pick fb2f677 Feature A is donefixup c5069d5 fixup! Feature A is donefixup c9e138f fixup! Feature A is done pick 733e2ff Feature B is done

This command has opened your editor with lines above. Just save & quit and ... :

$ (dev) git log --onelineff4de2a Feature B is done5478cee Feature A is doneac5db87 Previous commit

Your shameful commit has been merged properly with the original feature. It's just a shorcut for something you could do otherwise but I find it very convenient :).

That's all folks !

EDIT : git rebase i <after-this-commit> must be launched with as argument the last commit you want to retain as-is, not the first one you want to change.

本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/8034011.html如需转载请自行联系原作者

demoblog

你可能感兴趣的文章
[关于SQL]查询成绩都大于80分的学生
查看>>
Delphi(Tuxedo,BDE,ADO)三合一数据集组件HsTxQuery
查看>>
java之ibatis数据缓存
查看>>
“TNS-03505:无法解析名称”问题解决一例
查看>>
LeetCode - Longest Common Prefix
查看>>
Android图片处理
查看>>
2015年第21本:万万没想到,用理工科思维理解世界
查看>>
大家谈谈公司里的项目经理角色及职责都是干什么的?
查看>>
剑指offer
查看>>
Velocity魔法堂系列二:VTL语法详解
查看>>
NopCommerce架构分析之八------多语言
查看>>
转:Eclipse自动补全功能轻松设置
查看>>
ES6新特性:Javascript中的Reflect对象
查看>>
hibernate逆向工程生成的实体映射需要修改
查看>>
mysql update操作
查看>>
Robots.txt - 禁止爬虫(转)
查看>>
MySQL数据库
查看>>
项目分析_xxoo-master
查看>>
SQLServer2012自增列值跳跃的问题
查看>>
ViewBag对象的更改
查看>>