git pull 时出现 error: Your local changes to the following files would be overwritten by merge的解决办法

The most useful commands you will want to learn are

  • clone
  • status
  • pull
  • commit
  • push
  • gitk
  • stash
  • log
  • checkout
% git clone ssh://antportal.com:22/var/lib/git/rndtaxcredit.git
Cloning into rndtaxcredit...
remote: Counting objects: 1571, done.
remote: Compressing objects: 100% (1434/1434), done.
remote: Total 1571 (delta 907), reused 196 (delta 88)
Receiving objects: 100% (1571/1571), 4.59 MiB | 1.09 MiB/s, done.
Resolving deltas: 100% (907/907), done.

Stashing when pull doesn't work

% git pull
...error: Your local changes to the following files would be overwritten by merge:
    webfront/app/views/Projects/index.html
    webfront/app/views/main.html
Please, commit your changes or stash them before you can merge.

In those cases, you want to stash

% git stash
Saved working directory and index state WIP on master: 11f6d51 merge changes
HEAD is now at 11f6d51 merge changes

Then you pull...

rndtaxcredit/rndtaxcredit % git pull
...
5 files changed, 61 insertions(+), 69 deletions(-)

And finally you stash pop

% git stash pop
....
Dropped refs/stash@{0} (865bf3eef6b7752cff098dbf3dd20b2ffebb02f7)

git checkout is useful for switching between branches. A best practice, in conjunction with working with an issue tracker such as jira, is to create branches for each issue.

git checkout -b i777

where, issue 777 would be the issue number for this issue. This enables a convenient coupling between the name of your branches and the issues you are working on. "git checkout -b some_branch" is equivalent to the two commands "git branch some_branch" and "git checkout some_branch"

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当你在使用 SourceTree 操作 Git 遇到 "Your local changes to the following files would be overwritten by merge" 的错误提示,这意味着你正在尝试合并的分支与当前分支存在冲突。为了解决这个问题,你可以采取以下步骤: 1. 首先,你需要查看哪些文件发生了冲突。SourceTree 会在界面上用红色标记出发生冲突的文件。你可以点击这些文件,查看具体的冲突内容。 2. 接下来,你需要决定如何处理这些冲突。有两种常见的方法: a. 保留当前分支的更改:如果你认为当前分支的更改是正确的,可以选择保留它们。在 SourceTree 中,右键点击发生冲突的文件,选择 "Reset File to Previous Version"(重置文件到之前的版本)。这将撤销你在当前分支上的更改,使文件回到合并前的状态。 b. 保留要合并的分支的更改:如果你认为要合并的分支的更改更合适,可以选择保留它们。在 SourceTree 中,右键点击发生冲突的文件,选择 "Use Theirs"(使用他们的版本)。这将将文件恢复到要合并的分支上的状态。 3. 解决完所有冲突后,你需要提交更改。在 SourceTree 中,点击 "Commit"(提交)按钮,填写提交信息,然后点击 "Commit & Push"(提交并推送)按钮。 4. 最后,确保你的本地仓库与远程仓库同步。在 SourceTree 中,点击 "Pull"(拉取)按钮,以获取远程仓库的最新更改。 通过以上步骤,你应该能够解决使用 SourceTree 操作 Git 遇到的 "Your local changes to the following files would be overwritten by merge" 错误。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值