この記事を作った動機 単に、git pullして変更をリモートリポジトリからローカルリポジトリに反映しようと思ったときに、ローカルリポジトリ側に未反映の変更があり、衝突してマージに失敗することがある。そのような場合に、とにかくそのローカルリポジトリにある変更内容を破棄して、リモートリポジトリの変更を反映したいとき用に、記録をとりたい。
ローカルリポジトリの変更内容を保持しておきたいときは、git stash dropをする必要はない。
とにかくリモートリポジトリの変更内容を反映する例 リモートリポジトリの変更をローカルに反映しようとしてエラーになる git pull remote: Enumerating objects: 56, done. remote: Counting objects: 100% (56/56), done. remote: Compressing objects: 100% (15/15), done. remote: Total 56 (delta 41), reused 56 (delta 41), pack-reused 0 (from 0) Unpacking objects: 100% (56/56), 6.00 KiB | 79.00 KiB/s, done. From github.com:hello30190f/OneNoteAlternative c539ef0..a484d7c master -> origin/master Updating c539ef0..a484d7c error: Your local changes to the following files would be overwritten by merge: firstPrototype/backend/dataServer/notebookData/test/contents/test.json Please commit your changes or stash them before you merge. Aborting ローカルリポジトリの変更を退避する git stash Saved working directory and index state WIP on master: c539ef0 save 退避したローカルリポジトリの変更を破棄する git stash drop Dropped refs/stash@{0} (e64f70a6e978cf0a154795872e0b07f6530123aa) ローカルリポジトリの変更を退避または破棄したことで、衝突しなくなる git pull Updating c539ef0..a484d7c Fast-forward .../commands/notebookAndPage/createNotebook.py | 6 +- .../commands/notebookAndPage/deletePage.py | 4 +- .../commands/notebookAndPage/updatePage.py | 4 +- firstPrototype/backend/dataServer/helper/common.py | 3 +- .../backend/dataServer/interrupts/controller.py | 10 +-- .../notebookData/newnote/contents/test.md | 3 +- .../notebookData/newnote/contents/testa.md | 10 ++- .../dataServer/notebookData/newnote/metadata.json | 17 +++- .../notebookData/newnote/metadata.json.backup | 17 +++- .../notebookData/newntoe/contents/asfsdfsdsss.md | 4 +- .../dataServer/notebookData/newntoe/metadata.json | 13 ++- .../notebookData/newntoe/metadata.json.backup | 13 ++- .../notebookData/test/contents/test.json | 99 +++++++++++++++++++++- .../notebookData/test/contents/test/anArticle1.md | 13 ++- .../test/contents/test/test2/testaaaa.json | 53 +++++++++++- .../notebookData/test/contents/test1.json | 11 +++ .../dataServer/notebookData/test/metadata.json | 25 +++++- .../notebookData/test/metadata.json.backup | 25 +++++- .../backend/dataServer/type/pages/free.py | 2 +- .../backend/dataServer/type/pages/markdown.py | 2 +- .../src/modules/FakepagesPath.tsx | 16 +++- firstPrototype/note/architecture.md | 2 +- 22 files changed, 321 insertions(+), 31 deletions(-) create mode 100644 firstPrototype/backend/dataServer/notebookData/test/contents/test1.json 参考にしたサイトとか Git - git-stash Documentation
https://git-scm.com/docs/git-stash (2025年11月12日)