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

本文共 2416 字,大约阅读时间需要 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 and git 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.

转载地址:http://tpxll.baihongyu.com/

你可能感兴趣的文章
写sql语句时将时间格式“20110725”转化为格式2012年07月25日
查看>>
[Hadoop in China 2011] 蒋建平:探秘基于Hadoop的华为共有云
查看>>
heartbeat高可用+lvsDR
查看>>
方丈被害子女有没有权利继承遗产?
查看>>
java入门第一季5、6
查看>>
[转载] 闻一多——七子之歌
查看>>
针对tomcat日志乱码问题
查看>>
免费的协作和协同办公软件平台onlyoffice轻松部署
查看>>
WiFi覆盖下的生活 享受便利的同时 别忘记了安全
查看>>
关于ios 8 7 下的模态窗口大小的控制 代碼+場景(mainstoryboard)( Resizing UIModalPresentationFormSheet )...
查看>>
Linux软件包的管理--YUM
查看>>
Axis2发布webservice(1)--0配置发布
查看>>
Java Web笔记 – Servlet中的Filter过滤器的介绍和使用 编写过滤器
查看>>
我奋斗了18年,不是为了和你一起喝咖啡
查看>>
gearman简单介绍
查看>>
《Typecript 入门教程》 3、接口
查看>>
jsp的几种跳转比较
查看>>
用oracle查询当前数据库中的所有表
查看>>
决心书
查看>>
git 从版本控制中删除文件及.gitignore的用法
查看>>