git merge,rebase,reset

老分不清怎么用git merge 与 rebase 区别.
撤回的时候使用git reset 又忘了具体参数.

git log

显示提交的详细信息

commit 2ec3438b5c53932e928ec4284c5121acb86f2abb (HEAD -> mdfs-ng, origin/mdfs-ng)
Author: #小辉辉 <xxxx.com>
Date:   Tue Apr 17 17:30:22 2018 +0800

    clear : del unused code

git log –pretty=oneline

只显示commit id和提交的描述信息

2ec3438b5c53932e928ec4284c5121acb86f2abb (HEAD -> mdfs-ng, origin/mdfs-ng) clear : del unused code
8a78c5779328d2e48826b9203a50d596d508392f update : clear code by sonar

git reflog

可以查看所有分支的所有操作记录.包括已经删除commit记录

2a84922 HEAD@{158}: checkout: moving from hui-comment to devel
0d0b108 (master, hui-comment) HEAD@{159}: checkout: moving from master to hui-comment

HEAD

HEAD 意义
HEAD 提交的最新版本
HEAD^ 上一个版本
HEAD^^ 上上个版本
HEAD~100 往上100个版本
HEAD@{index} 提交索引

git reset

git reset --hard HEAD@{2}

git commit –amend

修改已经提交的信息

git rebase

合并

  1. 合并1~3条提交
    git rebase -i HEAD~3
    
    pick dc44d6b 根据sonar修改FixedLenChunkFingerIndexDB
    pick 8a78c57 update : clear code by sonar
    pick 2ec3438 clear : del unused code
    
    #将pick改为squash或者s,之后保存并关闭文本编辑窗口即可
    pick dc44d6b 根据sonar修改FixedLenChunkFingerIndexDB
    s 8a78c57 update : clear code by sonar
    s 2ec3438 clear : del unused code
    
  2. 指名要合并的版本之前的版本号
    git rebase -i 0d0b108
    
  3. 遇到冲突需要使用
    git add .  
    git rebase --continue  
    
  4. 取消
    git rebase --abort
    

Merging vs. Rebasing

The first thing to understand about git rebase is that it solves the same problem as git merge.

The Merge Option

git checkout feature
git merge master
#Or, you can condense this to a one-liner:
git merge master feature

The Rebase Option

git checkout feature
git rebase master

参考

(Git)合并多个commit

7. 用rebase合并
Merging vs. Rebasing

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.