git-如何使用未提交的更改进行拉取和合并?

git-如何使用未提交的更改进行拉取和合并?,git,Git,在处理一些未提交的文件时,我需要提取新代码。有冲突,所以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:我最后做了一个

在处理一些未提交的文件时,我需要提取新代码。有冲突,所以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:我最后做了一个
隐藏
,然后是
。现在如何合并对新拉的更改?如何在不破坏pull的新更改的情况下应用隐藏?

使用
stash
,然后
pull
,最后一次
stash pop

git stash
git pull
git stash pop

Git提供了关于其功能的优秀文档。对于这种情况,您需要stach,您可以通过以下几个示例进行查找:

在深入讨论合并之前,我需要注意,对于“从远程获取最新更改”任务,有两种类似的解决方案。 有关更多信息,请参阅。 我更喜欢rebase,因为它不会产生冗余的合并提交

不要害怕做出承诺。您可以轻松地使用它做任何您喜欢的事情(使用修改它,放弃它,并使用将所有更改弹出到worktree中),直到将其推到任何位置

答复1 答复2
此命令不会影响您使用
fetch
系列(
fetch
pull
,…)中的任何命令获得的提交。

只需提交,然后pull,这不会覆盖它们所做的更改吗?我需要在我正在进行的工作中合并到自我开始以来所做的更改中。@SRobertJames Git的设计方式是很难覆盖并意外丢失一些更改。为了能够“破坏”某些东西,您必须使用特殊的非默认键或参数。
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