shari-sushi / 0015Laboratory

My SandBox, PoC
0 stars 0 forks source link

commitの派生元を変更したい #41

Open shari-sushi opened 1 week ago

shari-sushi commented 1 week ago

V-Karaokeにて、docsブランチが作業ブランチのかなり後の方で派生させてしまったので、余計なフィルが多い。 (古いコミットに戻って派生すればよかったんだけど、ポートフォリオ作成当時にそんな発想は無かった。)

しかし、commitの派生元を変更できるようなので、developの1stコミットくらいから派生させたことにしたい。

Gitでブランチの派生元を間違えたときの解決方法(rebase –onto、cherry-pick)

そして、履歴改変なので先にここで動作確認したい。

shari-sushi commented 1 week ago

動作確認手順1:疑似状況作成

適当にその時のブランチから派生して

> git switch -c git_reset_onto
Switched to a new branch 'git_reset_onto'
このrepositoryで一番古いのコミットを探してきた 情報量が見るからに違う 最新 最古
image image

新規commit

> git commit -m "git rebase --ont試すよ"
[git_onto 488b066] git rebase --ont試すよ
 1 file changed, 13 insertions(+)
create mode 100644 git-onto.md

push

> git push origin git_reset_onto
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 4 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (14/14), 1.87 KiB | 382.00 KiB/s, done.
Total 14 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), completed with 1 local object.
remote: This repository moved. Please use the new location:
remote:   https://github.com/shari-sushi/0015Laboratory.git
remote:
remote: Create a pull request for 'git_reset_onto' on GitHub by visiting:
remote:      https://github.com/shari-sushi/0015Laboratory/pull/new/git_reset_onto
remote:
To https://github.com/sharin-sushi/0015docker.git
 * [new branch]      git_reset_onto -> git_reset_onto

履歴確認。増えてます。(commit時点で増えるけどね)

> git log --oneline  
b27888a (HEAD -> git_reset_onto, origin/git_reset_onto) reset --onto用
ae598a1 enumになってないけどまあ
da54cd3 ちょっと整理
7cf1ca1 (origin/ts_enum) enum
cd353b7 iroiro
11131c6 iroiro

この状態で、 「あー、このブランチって実際にコードを書く作業ブランチと違うから、.goとか.tsxとか不要なんだよな。邪魔だな」となるわけ。

↓のコメントで解決していく。

shari-sushi commented 1 week ago

動作確認手順2:履歴改変

派生元をcc37056に移行したい。

> git log --oneline --graph 
* 488b066 (HEAD -> git_onto, origin/git_onto) git rebase --ont試すよ
* ae598a1 (ts_enum) enumになってないけどまあ
* da54cd3 ちょっと整理
* 7cf1ca1 (origin/ts_enum) enum
* cd353b7 (issue/36-sort) iroiro
* 11131c6 iroiro
* 7051780 (origin/issue/36-sort) wip : tailswind効かないし、わけわからんくなったので
* 72b93a2 (origin/issue/35-nodb_api, issue/35-nodb_api) feat,fix ここまでまとめてcommitしちゃ
う
* b81a946 dockerfileにsampleディレクトリ追加 #35
* 241a35a dockerfile作成 #35
* 87d631d api作成 #35
* 8fe17dd (origin/issue/31-ci, issue/31-ci) working-directory追記 #31
* 6cecd40 working-directory追記 #31
* 1fc0a56 go_test記述、それを実行できるCIファイル記述
* 860c5e9 github-actions-demo.yml作成 #31
*   cacabca (origin/main, main) Merge pull request #29 from sharin-sushi/issue/28-tailwind_css
|\
| * 1e6d2f3 (origin/issue/28-tailwind_css) わからん
* | c80836a Update README.md
* | 95d1a28 Merge pull request #27 from sharin-sushi/issue/26-react_player
|\|
| * 9426e8f (origin/issue/26-react_player, issue/26-react_player) 終わり
| * fee1cd8 検証終了。無理。本家issueに投げた

git rebase --onto {本来親にしたかったブランチ} {間違って親にしてしまったブランチ名} {親を変更する作業ブランチ名}

$ git rebase --onto origin/master work/A work/B

そうか、commitじゃなくてbranch単位か…。 てことは、「一番古いbranch(の最新)から派生」に履歴改変するか、「一番古いcommitから新規branchを作成して、そこから派生させたことにする」…? 後者の方が良さげだけどそれはそれで履歴キモイ?

これはケースバイケースな気がする。 V-Karaokeの履歴を確認した結果、最古コミットから新branch作って、それを派生元にすることにした。(時間系列的な不整合発生しそう…。)

V-Karaokeの履歴を確認

| v-kara 最新1| v-kara最新2 | v-kara最古 | | --- | --- | --- | | architect-figure | [README&figure](https://github.com/shari-sushi/V-Kara-Lists/tree/README%26figure) | 最古のcommit | ![image](https://github.com/shari-sushi/0015Laboratory/assets/127638412/8168416a-6696-4e71-8de8-58602ade0376)| ![image](https://github.com/shari-sushi/0015Laboratory/assets/127638412/582d97a8-1fcb-4303-84d7-2b63dac1b821) | ![image](https://github.com/shari-sushi/0015Laboratory/assets/127638412/ede3cd64-b016-4af7-8665-7c43e2a2a0e8) | ※ついでに、architectじゃなくてarchitectureの方が正しいことに気づく やっぱ大分汚いので、最古コミットで良さそう。 `for-figure`って名前でブランチ作るか。

> git checkout cc37056
Note: switching to 'cc37056'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at cc37056 1st:過去にdocker入れたやつ。その後docker動作確認作業のため再利用予定。
ステージ前の差分扱いになってるw a b
image 「全ての変更を破棄」する。重すぎて一瞬フリーズ。
image

GUIだと1000件ずつしか変更削除できないっぽい。 git reset –hard HEAD^でいいかな→むりぽ