代码之家  ›  专栏  ›  技术社区  ›  Rudie

git:在新的/dirty/dev分支中提交对旧的/safe分支的更改,而不签出或丢失未过期的数据

  •  11
  • Rudie  · 技术社区  · 15 年前

    在我开始开发一些实验性的东西之前,我创建了一个新的分支。我通常会忘记这一点(这不是问题),但现在我提前做了。
    从那以后,我更新了3个文件。

    • 其中2个是我不希望提交给安全部门的实验性更改。
    • 在1中,只有安全的(小的)更改是我绝对希望提交给安全分支的。我对最后要提交给新分支的更改也很满意(但不是这样)。

    是否有可能(我确信是)从我的(脏的)工作目录(working dir)向一个旧的、安全的分支(safe branch)快速地提交一些未过期的、未提交的更改?


    this 'manual' for help

    3 回复  |  直到 8 年前
        1
  •  6
  •   VonC    15 年前

    x--x--x (safe)
           \
            <a,b,c> (3 private evolutions in exp branch)
    

    x--x--x--a (a committed only in safe banch)
           \
            b,c (b and c commited in exp branch)
    

    git add a
    git commit -m        # in exp branch, gasp!
    git stash save       # save the rest of the exp work in progress
    git checkout master
    git merge exp        # fast-forward merge
    
    x--x--x--a (safe,exp)
              \
               [b,c] (stashed)
    
    git branch -f exp HEAD~1  # reset branch exp to before 'a'
    git checkout exp
    git stash pop
    git add -A
    git commit -m "..."
    
    x--x--x--a (a committed only in safe banch)
          \
            b,c (b and c commited in exp branch)
    
        2
  •  7
  •   Chris Johnsen    15 年前

    git checkout

    --force --merge --conflict

    git checkout safe-branch
    git add -- files-with-safe-changes
    git commit
    git checkout -
    

    git add --patch

    git stash save
    git merge safe-branch
    git stash pop --index
    

    git checkout -m

    some‑file some-file

    -m

    git stash

    git stash save
    git checkout stash -- files-with-save-changes
    git checkout -m safe-branch
    git commit
    git checkout -
    git stash pop --index
    

    git checkout -p stash -- files git add -- files -p git stash save --keep-index git checkout stash -- files git stash --keep-index

    git checkout -f - && git stash pop

    git checkout -- files-with-safe-changes








        3
  •  0
  •   fseto    15 年前

    • 在“实验性”分支上创建一个新分支
    • 提交所需的任何未分页文件
    • 返回主服务器
    • cherrypick 无论您的“实验性”提交什么,以及步骤1中刚刚创建的新分支。
    • 回到“实验”分支