Resetting the Greet Branch
Goals
- Reset the greet branch to the point before the first merge.
Reset the greet branch
Let’s go back in time on the greet branch to the point before we merged master onto it. We can reset a branch to any commit we want. Essentially this is modifying the branch pointer to point to anywhere in the commit tree.
In this case we want to back greet up to the point prior to the merge with master. We need to find the last commit before the merge.
Execute:
git checkout greet
git hist
Output:
$ git checkout greet
Already on 'greet'
$ git hist
* 6938117 2020-06-20 | Merged master fixed conflict. (HEAD -> greet) [Jim Weirich]
|\
| * ee97f8e 2020-06-20 | Made interactive (master) [Jim Weirich]
* | a87176d 2020-06-20 | Merge branch 'master' into greet [Jim Weirich]
|\ \
| |/
| * 8d90176 2020-06-20 | Added README [Jim Weirich]
* | 228a31e 2020-06-20 | Updated Rakefile [Jim Weirich]
* | 98cfd8a 2020-06-20 | Hello uses Greeter [Jim Weirich]
* | cf0438b 2020-06-20 | Added greeter class [Jim Weirich]
|/
* 5aec14d 2020-06-20 | Added a Rakefile. [Jim Weirich]
* 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
* 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
* 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
* c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
* 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
* 4445720 2020-06-20 | First Commit [Jim Weirich]
That’s a bit hard to read, but looking at the data we see that the “Updated Rakefile” commit was the last commit on the greet branch before merging. Let’s reset the greet branch to that commit.
Execute:
git reset --hard <hash>
Output:
$ git reset --hard 228a31e
HEAD is now at 228a31e Updated Rakefile
Check the branch.
Look at the log for the greet branch. We no longer have the merge commits in its history.
Execute:
git hist --all
Output:
$ git hist --all
* ee97f8e 2020-06-20 | Made interactive (master) [Jim Weirich]
* 8d90176 2020-06-20 | Added README [Jim Weirich]
| * 228a31e 2020-06-20 | Updated Rakefile (HEAD -> greet) [Jim Weirich]
| * 98cfd8a 2020-06-20 | Hello uses Greeter [Jim Weirich]
| * cf0438b 2020-06-20 | Added greeter class [Jim Weirich]
|/
* 5aec14d 2020-06-20 | Added a Rakefile. [Jim Weirich]
* 721b979 2020-06-20 | Moved hello.rb to lib [Jim Weirich]
* 907a445 2020-06-20 | Add an author/email comment [Jim Weirich]
* 4254c94 2020-06-20 | Added a comment (tag: v1) [Jim Weirich]
* c8b3af1 2020-06-20 | Added a default value (tag: v1-beta) [Jim Weirich]
* 30c2cd4 2020-06-20 | Using ARGV [Jim Weirich]
* 4445720 2020-06-20 | First Commit [Jim Weirich]
当前内容版权归 gitimmersion 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 gitimmersion .