zoukankan      html  css  js  c++  java
  • git tips

    修改已提交的commit

    假设我们需要修改倒数第三个commit的内容

    1、首先调用`git rebase`

    git rebase -i HEAD~3
    

    此时会产生如下的提交列表

    pick f7f3f6d changed my name a bit
    pick 310154e updated README formatting and added blame
    pick a5f4a0d added cat-file
    
    # Rebase 710f0f8..a5f4a0d onto 710f0f8
    #
    # 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
    #
    # 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
    

    当需要更新相应的commit时,就将commit序列号之前的pick改为edit(可一次将多个pick修改为edit)

    退出编辑器,即处于该commit中

    2、在对commit进行修改之后,进行正常的git add,最后调用

    git commit --amend
    

    以及

    git rebase --continue
    

    进入下一个需要edit的commit,如果有的话

    3、重复步骤2,直到rebase完成

    删除中间的一些commit

    1、例如我有如下的commit列表:

    commit ae19158e451fdc8d1083cbc69efe2de7f55d3a5f
    commit f7fde5512806cd264ba8956e794112e218cbf870
    commit 3aefb191f767b3d8c435bc0b24f90f135213b675
    

      

    2、现在要删除commit f7fde5512

    一种方法是,记录下commit ae19158的哈希值,然后git reset --hard 3aefb19,最后git cherry-pick ae19158即可

    改变某个commit的作者和邮箱

    git commit --amend --author="Author Name <email@address.com>"
    

      

  • 相关阅读:
    mybatis date类型比较
    搭建 c 语言环境 1_centos6 minimal 配置 c/c++ 编译环境
    2_eclipse配置c/c++环境
    1_eclipse导入hibernate 的DTD 文件
    1_eclipse配置c/c++开发环境
    2_修改Eclipse里面的快捷键
    1_修改注释内容
    8_对象创建、static 关键字、静态变量和成员变量的区别、文档
    7_匿名对象、封装(private)、this 关键字、构造方法
    6_面向对象基础、成员变量和局部变量的区别
  • 原文地址:https://www.cnblogs.com/YaoDD/p/6269977.html
Copyright © 2011-2022 走看看