トピックブランチをマージしてないのにmain(master)に変更内容がmergeされてる...?
勉強不足で恐縮ですが、 topic branchをマージせず、checkoutしてmain branchに戻すだけで変更内容を消せると思っていた。
実際やってみたら、コンフリクトせず、topicで変更した内容が反映されているように見えた。
そこで、以下変更内容を完全に消すようにしたい。
$ git status
On branch topic-branch
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
deleted: app/assets/stylesheets/users.scss
modified: app/javascript/packs/application.js
modified: app/views/layouts/_rails_default.html.erb
Untracked files:
(use "git add <file>..." to include in what will be committed)
.DS_Store
app/.DS_Store
app/javascript/stylesheets/
no changes added to commit (use "git add" and/or "git commit -a")
・ステージングにあり、追跡されているが編集されているもの
・新たに追加されたため、追跡されていないもの
の二種類がある状態から、2ステップの作業を行っていく。
master branchから変更内容を削除する
上記記事を参考に変更内容をmaster branchから削除した。
まず、modifyされた内容を取り消す。
$ git checkout .
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
.DS_Store
app/.DS_Store
app/javascript/stylesheets/
nothing added to commit but untracked files present (use "git add" to track)
次に、ファイルが削除されたり、追加されたりしている、追跡対象外のファイルやディレクトリを削除する。
$ git clean -df .
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
これで全ての変更内容が取り消せた。
以上