DEV Community

Cover image for Resolving tricky situations with git reset and rebase 🧶

Resolving tricky situations with git reset and rebase 🧶

Alec Brunelle on May 08, 2019

Want more great content like this? visit: https://blog.alec.coffee You should care about how clean your Git history is. It provides a way to com...
Collapse
 
tonymet profile image
Tony Metzidis

great article

in case your changes are patches and not files, another good trick is

git add -p

A good example would be if you added some experimental methods in 3 different files, and you want to control which commits those changes get applied to.

Finally, it's important to remember your reflog

git reflog |head
471af9a HEAD@{0}: commit (initial): init

that keeps tracks of the history of all refs (e.g. "master" and all branches are refs). That way you can easily reset to a ref from a few days ago in case you forget which commit was kosher.

Collapse
 
aleccool213 profile image
Alec Brunelle

Another two fantastic under-rated commands.

Collapse
 
lukejs profile image
Luke • Edited

This is exactly what I have needed on several occasions, thanks for sharing! Also the clips were very handy in seeing what's going on - I just wish I could start them when I'm ready and play/pause/rewind.

What's doing the autocomplete preview? I need that in my life. 😍

Collapse
 
aleccool213 profile image
Alec Brunelle

Thanks for the feedback! I am super happy at least one person found this handy ❤️

I use the Fish shell which has context-aware auto-complete based on your historical data 🐟

Collapse
 
jessekphillips profile image
Jesse Phillips

Check out the --fixup commit.

Collapse
 
fpolster profile image
Florian Polster

Yeah, OP, checkout --fixup. It does what you describe in this post more conveniently

Collapse
 
aleccool213 profile image
Alec Brunelle

I'll check this out!

Collapse
 
gmtborges profile image
MacGyver

Nice, thanks for sharing. This rebase technique I have never seen before.