Bem*_*mis 160 git git-stash git-merge
我对我的分支进行了一些更改,并意识到我忘了我已经对所述分支进行了一些其他必要的更改.我想要的是一种将我的隐藏更改与当前更改合并的方法.
有没有办法做到这一点?
为了方便起见,我最终放弃并首先承诺了我目前的变化,然后是我的变化,但我宁愿一举将它们送进去.
Jos*_*ner 232
我刚刚发现如果你的未提交的更改被添加到索引(即"暂存",使用git add ...),那么git stash apply(并且,可能git stash pop),实际上将进行适当的合并.如果没有冲突,你就是金色的.如果没有,请像往常一样解决它们git mergetool,或者使用编辑器手动解决它们.
要清楚,这是我正在谈论的过程:
mkdir test-repo && cd test-repo && git init
echo test > test.txt
git add test.txt && git commit -m "Initial version"
# here's the interesting part:
# make a local change and stash it:
echo test2 > test.txt
git stash
# make a different local change:
echo test3 > test.txt
# try to apply the previous changes:
git stash apply
# git complains "Cannot apply to a dirty working tree, please stage your changes"
# add "test3" changes to the index, then re-try the stash:
git add test.txt
git stash apply
# git says: "Auto-merging test.txt"
# git says: "CONFLICT (content): Merge conflict in test.txt"
Run Code Online (Sandbox Code Playgroud)
......这可能就是你要找的东西.
跑git add第一.
Bra*_*dan 69
运行git stash pop或git stash apply基本上是合并.您不应该提交当前更改,除非在存储中更改的文件也在工作副本中更改,在这种情况下您将看到此错误消息:
error: Your local changes to the following files would be overwritten by merge:
file.txt
Please, commit your changes or stash them before you can merge.
Aborting
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您无法一步将存储应用于当前更改.git rebase如果你真的不想要两次提交,你可以提交更改,应用存储,再次提交,并压缩这两个提交,但这可能会更麻烦,值得.
ks1*_*322 23
我想要的是一种将我的隐藏更改与当前更改合并的方法
这是另一种选择:
git stash show -p|git apply
git stash drop
Run Code Online (Sandbox Code Playgroud)
git stash show -p将显示上次保存的藏匿的补丁.git apply将适用它.合并完成后,可以删除合并的存储git stash drop.
| 归档时间: |
|
| 查看次数: |
106750 次 |
| 最近记录: |