| Page 1 of 1 |
|
|
Posted: Thu, 9th Dec 2021 21:09 Post subject: Git question |
|
 |
Hey Git cracks, I have a short question:
Let's say I have multiple commits into master:
A, B, C, D, HEAD
now I want to revert D, C and B so that I'm "back" at A, but I also want to keep the changes from B, C and D in a seperate branch (one branch, containing all changes in this order), so that I can merge them at a later time?
|
|
| Back to top |
|
 |
|
|
Posted: Thu, 9th Dec 2021 22:26 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 23:03; edited 5 times in total
|
|
| Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 74357
Location: Israel
|
Posted: Thu, 9th Dec 2021 22:39 Post subject: |
|
 |
Create a branch from the point you are in (D).
Then go back to your previous branch and move HEAD to A.
|
|
| Back to top |
|
 |
|
|
Posted: Thu, 9th Dec 2021 22:43 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 23:03; edited 2 times in total
|
|
| Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 74357
Location: Israel
|
Posted: Thu, 9th Dec 2021 22:51 Post subject: |
|
 |
| Code: | ➜ Desktop mkdir git-test
➜ Desktop cd git-test
➜ git-test git init
Initialized empty Git repository in /Users/lnatan/Desktop/git-test/.git/
➜ git-test git:(master) touch a.txt && git add -A && git commit -m "A"
[master (root-commit) caef74f] A
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
➜ git-test git:(master) touch b.txt && git add -A && git commit -m "B"
[master 9f497b4] B
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
➜ git-test git:(master) touch c.txt && git add -A && git commit -m "C"
[master 27ec611] C
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 c.txt
➜ git-test git:(master) touch d.txt && git add -A && git commit -m "D"
[master 83f0d91] D
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 d.txt
➜ git-test git:(master) git --no-pager log
commit 83f0d91ddcbe253e8c0d4e01ddf87d30e368b33b (HEAD -> master)
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:46:02 2021 +0200
D
commit 27ec611f7c7d47a24866e2525d7a4d7bfc81bb0a
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:50 2021 +0200
C
commit 9f497b40c175e493b724470ec5b0f4fb79fa8459
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:41 2021 +0200
B
commit caef74f9cb2b01de5437e16b387b2c266b4f39be
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:20 2021 +0200
A
➜ git-test git:(master) git checkout -b bcd
Switched to a new branch 'bcd'
➜ git-test git:(bcd) git --no-pager log
commit 83f0d91ddcbe253e8c0d4e01ddf87d30e368b33b (HEAD -> bcd, master)
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:46:02 2021 +0200
D
commit 27ec611f7c7d47a24866e2525d7a4d7bfc81bb0a
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:50 2021 +0200
C
commit 9f497b40c175e493b724470ec5b0f4fb79fa8459
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:41 2021 +0200
B
commit caef74f9cb2b01de5437e16b387b2c266b4f39be
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:20 2021 +0200
A
➜ git-test git:(bcd) git checkout master
Switched to branch 'master'
➜ git-test git:(master) git reset --hard caef74f9cb2b01de5437e16b387b2c266b4f39be #The "A" commit
HEAD is now at caef74f A
➜ git-test git:(master) git --no-pager log
commit caef74f9cb2b01de5437e16b387b2c266b4f39be (HEAD -> master)
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:20 2021 +0200
A
➜ git-test git:(master) git merge bcd
Updating caef74f..83f0d91
Fast-forward
b.txt | 0
c.txt | 0
d.txt | 0
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
create mode 100644 c.txt
create mode 100644 d.txt
➜ git-test git:(master) git --no-pager log
commit 83f0d91ddcbe253e8c0d4e01ddf87d30e368b33b (HEAD -> master, bcd)
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:46:02 2021 +0200
D
commit 27ec611f7c7d47a24866e2525d7a4d7bfc81bb0a
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:50 2021 +0200
C
commit 9f497b40c175e493b724470ec5b0f4fb79fa8459
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:41 2021 +0200
B
commit caef74f9cb2b01de5437e16b387b2c266b4f39be
Author: Leo Natan <leonatan@invisionapp.com>
Date: Thu Dec 9 23:45:20 2021 +0200
A |
It just works.
|
|
| Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 74357
Location: Israel
|
Posted: Thu, 9th Dec 2021 22:53 Post subject: |
|
 |
If you have a remote, you will need to push --hard after resetting the original branch.
|
|
| Back to top |
|
 |
|
|
Posted: Thu, 9th Dec 2021 22:58 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 23:03; edited 2 times in total
|
|
| Back to top |
|
 |
|
|
Posted: Thu, 9th Dec 2021 23:17 Post subject: |
|
 |
Last edited by AmpegV4 on Mon, 23rd Feb 2026 09:02; edited 1 time in total
|
|
| Back to top |
|
 |
|
|
Posted: Thu, 9th Dec 2021 23:35 Post subject: |
|
 |
Last edited by paxsali on Thu, 4th Jul 2024 23:03; edited 2 times in total
|
|
| Back to top |
|
 |
|
|
Posted: Thu, 9th Dec 2021 23:46 Post subject: |
|
 |
Last edited by AmpegV4 on Mon, 23rd Feb 2026 09:02; edited 1 time in total
|
|
| Back to top |
|
 |
|
|
Posted: Fri, 10th Dec 2021 00:36 Post subject: |
|
 |
We do use a process similar to gitflow and only commit production ready code to master, but the guy is new to the project and he just worked on a feature and when he thought it was done it was merged to master..(incl. delete feature branch) and then a bug was found... so he created a new branch from master and merged it again.. and then again. this happened over 3 weeks. No other code was luckily merged into that project (but one guy might've created a new branch based on master inbetween that time). So we want to roll back all 3 commits by our dude, because other teams need to deliver some other app first and we'll keep his stuff in a feature branch until they are ready to commit back into the codebase... it's a mess. His stuff shouldn't have been merged in the first place :/
|
|
| Back to top |
|
 |
LeoNatan
☢ NFOHump Despot ☢
Posts: 74357
Location: Israel
|
Posted: Fri, 10th Dec 2021 01:17 Post subject: |
|
 |
Follow what did it. That’s how you do it.
|
|
| Back to top |
|
 |
|
|
Posted: Fri, 10th Dec 2021 01:25 Post subject: |
|
 |
Last edited by AmpegV4 on Mon, 23rd Feb 2026 09:02; edited 1 time in total
|
|
| Back to top |
|
 |
|
|
Posted: Fri, 10th Dec 2021 01:49 Post subject: |
|
 |
Nah we are really not hard on him, we just want to make sure that we properly roll back and keep the changes. Actually if the other teams had listened to our architectural decisions from two months ago, we wouldn't have to roll back shit, because their changes would've been ready :/
|
|
| Back to top |
|
 |
|
|
Posted: Fri, 10th Dec 2021 09:37 Post subject: ***** |
|
 |
*****
Last edited by Areius on Fri, 19th Sep 2025 16:27; edited 1 time in total
|
|
| Back to top |
|
 |
|
|
Posted: Wed, 16th Nov 2022 08:30 Post subject: |
|
 |
Last edited by AmpegV4 on Mon, 23rd Feb 2026 08:56; edited 1 time in total
|
|
| Back to top |
|
 |
|
|
Posted: Sun, 22nd Jan 2023 23:09 Post subject: |
|
 |
|
|
|
| Back to top |
|
 |
| Page 1 of 1 |
All times are GMT + 1 Hour |