我怎样才能拉新更新并忽略现有更改?

问题描述 投票:0回答:2

运行 git 命令时出现此错误 git pull origin mastermy server repository.

please, commit your changes or stash them before you can merge. aborting in 
 run of pull command

我在运行这个程序时遇到了很多次。为了解决这个问题,我尝试了git reset --hard。但是还有其他解决方案。

实际上问题是我在 pull 之前做了一些更改,现在 master 在我工作的同一个文件中做了一些更改。所以我确实想推动当前的变化并接受来自主分支或其他分支的新变化。

git github git-pull
2个回答
1
投票

我的经验是,当错误或冲突发生时,遵循 Git 客户端指令。

在合并之前提交您的更改或存储它们。

因此,

(1)

git stash

(2) 合并

(3)

git stash pop


0
投票

是的 git

git stash
是一个选项,但有时我们必须保留当前更改,然后我们可以做一件事,我们可以从当前分支创建新的临时分支,然后隐藏旧分支。所以通过这种方式我们可以将当前代码复制到临时分支并接受来自新分支的新提交。

为此我们必须创建新的分支。

    git checkout -b  <temporary_branch_name> 

    git merge <current_branch> // optional. because git checkout automatally  do it.

    git checkout <old branch name >  // come back on disputed branch

    git   stash  // remove current changes.

    git pull origin <branch_name> // for accept new changes.
© www.soinside.com 2019 - 2024. All rights reserved.