Last active
May 1, 2025 07:04
Revisions
-
mbjones revised this gist
May 1, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ Note that my changes are now uncommitted in the README.md file: <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/e9391fbc-0f66-4756-bcd2-a679f63a80e8" /> So, now I can do what I shoud have done before, and merge main into develop to create a clean starting point for new changes. <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/1c673810-242c-45cc-86ff-2e251e8092c2" /> -
mbjones revised this gist
May 1, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ because the merge commit in main wasn't committed into develop. This makes for a <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/4e3c21be-d298-4842-ac1d-993546a6ee06" /> What if I want to go back and clean it up? First, I can do a soft reset to return to the state before I did my commit. In this case, the `develop` branch returns to where it was, and my changes are left uncommitted in the README file. I can run the command `git reset --soft ad29acc8` to bring the develop branch back to where it was. -
mbjones created this gist
May 1, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ # git reset I often mess up. Sometimes badly :exploding_head:. `git reset` is my friend. Here's the current state of the Metacat repo: <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/2e4509ae-bb20-4539-bed8-013352f65f1f" /> Imagine I commit a file to develop. When I look at the log, I see its gotten pretty messy, because the merge commit in main wasn't committed into develop. This makes for a messy tree. <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/4e3c21be-d298-4842-ac1d-993546a6ee06" /> What if I want to go back and clean it up. First, I can do a soft reset to return to the state before I did my commit. In this case, the `develop` branch returns to where it was, and my changes are left uncommitted in the README file. I can run the command `git reset --soft ad29acc8` to bring the develop branch back to where it was. <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/2e4509ae-bb20-4539-bed8-013352f65f1f" /> Note that my changes are now uncommitted in the README.md file: <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/e9391fbc-0f66-4756-bcd2-a679f63a80e8" /> So, now I can do what I shoud have done before (or the developer who merged `develop` into main should have done), and merge main into develop to create a clean starting point for new changes. <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/1c673810-242c-45cc-86ff-2e251e8092c2" /> :tada: :tada: :tada: Now I have a clean tree. Note that both `develop` and `main` point at the same commit hash: <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/2fff2876-85f2-4405-8e89-c13c6201efc0" /> And I can redo my commit (`git add README.md; git commit`), which results in a linear history with my changes to README: <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/cc8e1905-aa69-4dd5-956e-2652858a7f8e" /> Now I have a clean, linear history, but I added some garbage into develop. What if I want to just go back? This is a job for `git reset --hard`, which moves the branch back to the original commit and discards all of the changes. Be careful, **you can lose stuff here with no way to get it back!** <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/3212478a-15cb-48ac-85f4-80f5cf9ad5c5" /> Et voila! We're back where we started. :sunglasses: It's like we were never even here. (Not really, though, appearances can be deceiving.) <img width="1350" alt="image" src="https://gist.github.com/user-attachments/assets/d1446af6-4f76-4b2d-ad47-340b76f30a40" /> One last warning. git reset rewrites history. So, this is super useful before you push. Once you've pushed, your history is shared for everyone to see, you can't really use reset like this, and you'll need to be more strategic to cover your tracks. Don't rewrite history in shared repositories, it messes with everyone's day.