这个问题的简短版本是:如何在git不触发自动合并的情况下弹出存储?
现在为更长的版本......
考虑以下玩具示例替代git stash ... + git pull ... + git pop.
首先,git status显示工作目录中的唯一修改是某个跟踪文件foo.
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
现在,为了工作目录重置为干净的状态,作为一个先决条件的运行git pull,我暂时命名修改后的文件foo(一些未经跟踪的名称),并恢复的版本foo中HEAD...
% mv foo foo.$(date +%Y%m%dT%H%M%S)
% git checkout foo
% git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# foo.20130508T110014
nothing added to commit but untracked files present (use "git add" to track)
Run Code Online (Sandbox Code Playgroud)
好的,现在我跑了git pull,为了这个例子,我们假设是快进:
% git pull
Run Code Online (Sandbox Code Playgroud)
最后,我恢复暂时重命名foo.
% mv foo.20130508T110014 foo
Run Code Online (Sandbox Code Playgroud)
......我回来了
% git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: foo
#
Run Code Online (Sandbox Code Playgroud)
这是a的"道德等价物" git stash save + git pull + git stash pop,除了前者,而不是后者,不受"合并冲突"的影响,如下所示:
% git stash save 'WIP'
% git pull
% git stash pop
Auto-merging foo
CONFLICT (content): Merge conflict in foo
Run Code Online (Sandbox Code Playgroud)
我怎样才能复制rename-checkout-pull-rename上述使用顺序git stash save + ... + git stash pop,而不触发自动合并?
顺便提一下,rename-checkout-...-rename例程更接近于我对所谓的命令的期望stash.换句话说:现在保存我的工作目录的状态,并在以后替换它.这幅画中没有"合并".
我姗姗来迟地意识到,git已经提供了一个非常简单的解决方案来解决这个问题的动机(即自动合并可能将存储库置于"未合并状态").
所有人需要做的就是使用
git stash branch <branchname> [<stash>]
Run Code Online (Sandbox Code Playgroud)
而不是git stash pop(或git stash apply).
这会以保证没有冲突的方式弹出存储. 容易 - 柠檬 - 挤压.
stash 合并,这就是它的工作原理.
可以实现与非合并-Y藏匿write-tree read-tree和checkout-index. 这是一个实现原始测试环境的实例.
为了强制执行一个不合并的存储应用,你可以例如
git read-tree stash^{tree}
git checkout-index -af
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6916 次 |
| 最近记录: |