Git でローカルリポジトリの変更を退避、破棄する

この記事を作った動機 単に、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日)

November 12, 2025

ローカルリポジトリをリモートへアップロード

この記事を作った動機 単にすでに存在する、git リポジトリを LAN 内の Gitea 上にアップロードするための方法の簡易的なメモ。Githubの場合でも同じようなことはできると思う。(そもそも github のページ参考にしたし) やり方 リポジトリの URL は、“https://aaa.info/urlToAremoteRepo.git" と仮定している。 リポジトリの作成(リモート側) リモート側に、最小構成で、readme や license、gitignore を追加しないようにして空っぽのリポジトリを作成する。 リポジトリの URL を設定する(ローカル側) git remote add origin https://aaa.info/urlToAremoteRepo.git ブランチの確認(ローカル側) アップロードしたいブランチの確認。今回は “master” という名前のブランチを、リモートにアップロードする。 git branch * master アップロード(ローカル側) git push origin master リポジトリが設定できたかの確認方法 git remote -v origin https://aaa.info/urlToAremoteRepo.git (fetch) origin https://aaa.info/urlToAremoteRepo.git (push) 参考にしたサイトとか Adding locally hosted code to GitHub - GitHub Docs https://docs.github.com/en/migrations/importing-source-code/using-the-command-line-to-import-source-code/adding-locally-hosted-code-to-github (2025年5月19日)

May 19, 2025

git に証明書を追加する

この記事を作った動機 最近、いろいろ作ってみてはファイルがあっちゃこっちゃ行ってぐちゃぐちゃになっていたので、整理の一環として、LAN内で Gitea なるものを動かしてみている そこで、内部ネットワークで使っている証明書を windows 側にいれても git がそれを直接は使ってくれなかったので、SSL 証明書の設定の仕方を自分用に記録するだけ。(すぐ忘れるし) やり方 # 多分 global オプションはつけないほうがいいかも。全体的に証明書情報を変えてしまい、ほかのリポジトリで、githubから何かしようとか思ったとき、多分証明書が合わなくてエラーを吐いてしまう。 # git config --global http.sslCAInfo /path/to/cert.pem git config http.sslCAInfo /path/to/cert.pem 参考にしたサイトとか configure Git to accept a particular self-signed server certificate for a particular https remote - Stack Overflow https://stackoverflow.com/questions/9072376/configure-git-to-accept-a-particular-self-signed-server-certificate-for-a-partic (2025年5月11日)

May 11, 2025

ssh 経由でクローンできる git リポジトリを作るメモ

この記事を書いた動機 単に、リポジトリを作るところまではうまく行っていたのですが、リポジトリをクローンするときに、ユーザ名の指定をわかっておらず、ずっと以下のように間違った"git"というユーザを指定し続けていてなかなか気づけなかったということがあったのでメモすることにしました。 git clone git@[serveradress]:/Path/To/Target/Proejct/Root/Folder ちなみに、間違ったユーザを指定していると、ssh接続できないので、ずっと"Permission denied (publickey).“と言われ続けます。。。最初はなんでssh コマンド経由でつながるのに、gitではうまくいかないのかみたいになっていましたが、結局のところ間違ったユーザを意図せず指定し続けていただけなのでした。。。 リポジトリを作る cd /Path/To/Target/Proejct/Root/Folder git init --bare リポジトリをクローン git clone [username]@[serveradress]:/Path/To/Target/Proejct/Root/Folder 参考にしたサイトとか debugging - How can I debug git/git-shell related problems? - Stack Overflow https://stackoverflow.com/questions/6178401/how-can-i-debug-git-git-shell-related-problems (2025年3月10日) Git - Setting Up the Server https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server (2025年3月10日) Why doesn’t my SSH key work for connecting to github? - Stack Overflow https://stackoverflow.com/questions/9960897/why-doesnt-my-ssh-key-work-for-connecting-to-github (2025年3月10日) ChatGPT https://chatgpt.com/ (2025年3月10日)

March 10, 2025