0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

git pull origin masterしたら「error: Your local changes to the following files would be overwritten by merge」となる

Posted at

事象

masterブランチを親とするfeatureブランチをチェックアウトした状態でgit pull origin masterをしたら、「error: Your local changes to the following files would be overwritten by merge」となった。

$ git branch
  master
* feature
$ git pull origin master
From github.com:Example-Git/api-repo
 * branch            master     -> FETCH_HEAD
Updating 5966be1..1c8aaff
error: Your local changes to the following files would be overwritten by merge:
        Makefile
Please commit your changes or stash them before you merge.
Aborting

原因

masterブランチの変更により上書きされるファイルMakefileが、ローカルのfeatureブランチで変更されたまま未コミットであったためだった。

$ git status
On branch feature
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   Makefile

no changes added to commit (use "git add" and/or "git commit -a")

解消

Makefileの変更はコミット不要だったので、git checkoutにより変更を破棄したら正常にgit pull origin masterできた。

$ git checkout Makefile
$ git status
On branch feature
nothing to commit, working tree clean
$ git pull origin master
From github.com:Example-Git/api-repo
 * branch            master     -> FETCH_HEAD
Updating 5966be1..1c8aaff
Fast-forward
 Makefile                                                     |    3 +-
 sam.yml                                                      |   26 +
 2 files changed, 28 insertions(+), 1 deletions(-)
 create mode 100644 src/handlers/__init__.py

以上

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?