您的位置:首页 > 其它

Git 基本操作(二)

2018-08-11 23:02 489 查看

1. 分支操作

1.1 Fast-forward

  • 当被合并分支(C4)位于合并分支(C2)的历史线上,此时的合并称为"fast-forward";

// hotfix 被合并到 master
$ git merge hotfix

1.2 常见操作

  • git branch -v
    : 查看各个分支最后一次提交的说明
  • git branch -vv
    : 查看本地各个分支跟踪的远程分支;

  • git branch --merged
    : 查看已合并分支;
  • git branch --no-merged
    : 查看未合并分支;
  • git branch -d 分支名
    : 删除分支;
  • git branch -D 分支名
    : 强制删除分支;
  • git checkout -b 本地分支 远程分支
    : 以远程分支为基础,创建新分支;因为远程分支clone下来后,不能直接在本地操作;例如:
    git checkout -b serverfix origin/serverfix
  • git checkout --track origin/serverfix
    : 和上面操作等同;
  • git checkout serverfix
    : 和上面操作等同,不过,得满足:1)该分支不存在;2)远程分支只有一个同名的;

1.3 Rebasing

  • Rebase: 可以让操作的历史记录更干净;
$ git checkout experiment
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: added staged command

  • git rebase --onto master server client

  • git rebase <basebranch> <topicbranch>
    : 在master分支上执行;

1.3.1 Rebasing 注意事项

  • Do not rebase commits that exist outside your repository.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: