V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
tabris17
V2EX  ›  问与答

git 版本合并后有时候会分叉,有时候却是一条线?

  •  
  •   tabris17 · 2015-01-13 11:03:38 +08:00 · 5236 次点击
    这是一个创建于 3409 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如图:

    提交合并后仍然是一条线
    
    提交合并后有分叉
    
    第 1 条附言  ·  2015-01-13 11:46:31 +08:00
    我知道原因了,在.git/config里,那个一条线的项目设置了 rebase = true
    12 条回复    2015-01-13 11:46:06 +08:00
    tabris17
        1
    tabris17  
    OP
       2015-01-13 11:07:53 +08:00
    本地分支都跟踪了远程分支
    chmlai
        2
    chmlai  
       2015-01-13 11:09:47 +08:00   ❤️ 1
    fast-forward 就会一条线. 否则就分叉.
    合并的时候使用参数 --no-ff 就总是分叉.
    tabris17
        3
    tabris17  
    OP
       2015-01-13 11:11:30 +08:00
    但是我很确定没有勾选 --no-ff 选项呀
    tabris17
        4
    tabris17  
    OP
       2015-01-13 11:11:47 +08:00
    @chmlai 但是我很确定没有勾选 --no-ff 选项呀
    chmlai
        5
    chmlai  
       2015-01-13 11:15:05 +08:00
    @tabris17 没勾 --no-ff, 就取决于你原来的分支, 在开分支之后有没有新的 commit, 有就不能 fast-forward,
    没有就默认 fast-forward(一条线)
    anytk
        6
    anytk  
       2015-01-13 11:21:19 +08:00   ❤️ 1
    如果可以 Fast Forward,那么默认会 FF,不然会创建一个 Merge Commit。

    设定好 Work Flow ,我比较喜欢 FF 的线性风格。推荐一篇文章: https://sandofsky.com/blog/git-workflow.html
    NemoAlex
        7
    NemoAlex  
       2015-01-13 11:21:22 +08:00   ❤️ 1
    如果有 merge 的话肯定就不是一条线了啊。如果没有 merge 就只是 fast forward 当然就是一条线了。
    如果两个人改的根本不是一个东西,不需要 merge,那如何避免 merge 呢?做 rebase。
    这个给你参考 http://stevenharman.net/git-pull-with-automatic-rebase
    还有一种情况,你在 pull 的时候自动 rebase 了,而自己不知道。所以即便有 merge 也被 rebase 掉了。
    9hills
        8
    9hills  
       2015-01-13 11:25:12 +08:00   ❤️ 1
    在分支合并到master之前,现在分支上 git rebase master一下
    tabris17
        9
    tabris17  
    OP
       2015-01-13 11:27:39 +08:00
    @chmlai 但问题是那个一条线的分支也是有交叉提交的,但是合并后仍然是一条线。另外奇怪的是:

    pull之后那个一条线的项目提示信息和有分叉的项目提示信息不一样:

    一条线的项目提示:
    = [up to date] dev -> origin/dev
    = [up to date] master -> origin/master
    Current branch dev is up to date.


    而有分支的项目完成提示是:
    = [up to date] dev -> origin/dev
    = [up to date] master -> origin/master
    Already up-to-date
    tabris17
        10
    tabris17  
    OP
       2015-01-13 11:30:59 +08:00
    @9hills 我是怀疑那个一条线的分支给我自动rebase了,但是又找不到两者配置的区别
    9hills
        11
    9hills  
       2015-01-13 11:38:22 +08:00
    @tabris17 如果你就是喜欢一条线,那么:

    1. 每次都rebase master后再merge,而且每次merge的时候都加

    --ff-only
    Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved
    as a fast-forward.

    这个参数来保证每次都是fast-forward,避免出现分支

    2. git pull的时候用 git pull --rebase
    tabris17
        12
    tabris17  
    OP
       2015-01-13 11:46:06 +08:00
    我知道原因了,在.git/config里,那个一条线的项目设置了 rebase = true
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2903 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:30 · PVG 23:30 · LAX 08:30 · JFK 11:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.