[英]git - How can I pull and merge with my uncommitted changes?
在处理一些未提交的文件时,我需要提取新代码。 有冲突,所以git拒绝拉:
error: Your local changes to the following files would be overwritten by merge:
...
Please, commit your changes or stash them before you can merge.
问题1:如何提取和合并我未提交的更改? 我需要继续工作,我还没准备好提交,但我想要外部代码?
问题2:我最后做了一个stash
然后pull
。 我现在如何将我的更改合并到新拉? 如何在不破坏拉动的新变化的情况下应用我的藏品?
使用stash
,然后pull
,最后一个stash pop
。
git stash
git pull
git stash pop
在深入合并之前,我需要注意有两个类似的解决方案,用于“从远程获取最新更改”的任务。 有关更多信息,请参阅git pull VS git fetch git rebase 。 我更喜欢rebase,因为它不会产生冗余的合并提交。
不要害怕做出承诺。 你可以轻松地用它做任何你喜欢的事情(用git commit --amend
修改它,丢弃它并用git reset HEAD~1
所有更改弹出到worktree),直到你把它推到任何地方。
git add . # stage all changes for commit
git commit -m 'Tmp' # make temporary commit
git fetch $RemoteName # fetch new changes from remote
git rebase $RemoteName/$BranchName # rebase my current working branch
# (with temporary commit) on top of fethed changes
git reset HEAD~1 # discard last commit
# and pop all changes from it into worktree
git stash pop # this retrieves your changes
# from last stash and put them as changes in worktree
此命令不会影响使用fetch
family ( fetch
, pull
,...)中的任何命令获得的提交。
Git提供了有关其功能的出色文档。 对于这种情况,你需要stach,你可以在以下几个例子中查找: https ://git-scm.com/book/en/v1/Git-Tools-Stashing
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.