这个问题的简短版本是这样的:如何在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")
现在,为了将工作目录重置为干净状态,作为运行的先决条件git pull
,我暂时将修改后的文件重命名foo
(为一些未跟踪的名称),并恢复foo
in 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)
好的,现在我运行git pull
,为了这个例子,我们可以假设它是一个快进:
% git pull
最后,我恢复了临时重命名的foo
.
% mv foo.20130508T110014 foo
...我又回来了
% 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
#
这是 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
如何在不触发自动合并的情况下rename-checkout-pull-rename
使用 复制上述序列?git stash save + ... + git stash pop
顺便说一句,该rename-checkout-...-rename
例程更接近于我对名为stash
. 换句话说:现在保存我的工作目录的状态,稍后替换它。这张照片中没有“合并”。