分支进阶与版本回退

Fast-Forward

  1. 如果可能,合并分支时 Git 会使用 fast-forward 模式。
  2. 在这种模式下,删除分支时会丢掉分支信息
  3. 合并时加上 –no-ff 参数会禁用 fast-forward ,这样会多出一个 commit id
    1
    git merge --no-ff new_branch
  4. 查看 log
    1
    2
    git log --graph # 以图形化的方式
    git log --graph --abbrev-commit # log 日志中 commit_id 信息简写

版本回退

  1. 把当前文件目录下的所有文件放入暂存区,然后提交
    1
    2
    3
    4
    git commit -am 'add another line' 
    # 上述命令等价于以下两命令之和
    git add .
    git commit -m 'add another line'
  2. 回退到上一版本
    1
    2
    git reset --hard HEAD^
    git reset --hard HEAD~1
  3. 返回到某一版本
    1
    2
    git reflog # 查看操作日志,查看版本的 commit_id
    git reset --hard commit_id # 回退到特定版本