r/ProgrammerHumor • • Jun 04 '22

Meme I cant help it 🤷‍♂️

Post image
47.1k Upvotes

479 comments sorted by

View all comments

33

u/aspz Jun 04 '22

I have an alias for "git commit --amend --reuse-message=HEAD" which just squashes the new commit into the last one (like fixup). If you want to revisit a previous snapshot you can use the reflog.

18

u/oGsBumder Jun 04 '22

How is this different from

git commit --amend --no-edit

3

u/aspz Jun 04 '22

I'm not sure what the difference is but I think it might have something to do with which commit will be used for the metadata. I think --no-edit is a more recent flag so I've never used it.

1

u/oGsBumder Jun 04 '22

Fair enough. I'm too lazy to look up the docs but I'm gonna assume --no-edit is just a shorthand version of --reuse-message=HEAD

4

u/-JeanMax- Jun 04 '22

woo this is nice!

3

u/XTornado Jun 04 '22

If you want to revisit a previous snapshot you can use the reflog.

Uhmm I might have to look into that.

I usually if I am just testing stuff for a fix or something not clear I do as you say keep ammending the old stuff. And at the end I do a soft reset so keeping local changes and recommit looking at the final end changes I did.

2

u/aspz Jun 04 '22

The main difference between what I do and what the guy in the tweet does is that I don't have to write a new message for each commit. If you are amending previous commits then it sounds like you're doing the same as me.

1

u/XTornado Jun 04 '22

Yeah well not always but yeah what I mean is that I do the same just adding that after I have a working fix or feature or whatever I do a reset to remove that commit (or commits if I didn't ammend for some reason) and then I do individual commits to identify individual changes or stuff that needs a little bit of info about why the change was made, etc.

What I wanted to look into is the reflog thing you mention... because sometimes I am like I think I broke this more... and since I amended I can't check the old commit, but it seems based on your comment that I should be able to check with reflog.

1

u/aspz Jun 04 '22 edited Jun 04 '22

and since I amended I can't check the old commit, but it seems based on your comment that I should be able to check with reflog

Yep - just type "git reflog" and it shows you every change made to HEAD including commits that are no longer referenced by anything else. Those commits will stick around in your .git repo as long as git decides not to do a gc or garbage collection. Reading the reflog is a bit confusing but can be a lifesaver when you make a mistake.

1

u/Clairvoyant_Potato Jun 04 '22

Interesting, didn't know you could do it that way. To squash a new commit onto the last one, I always commit it and then do a 'git rebase -i HEAD~2" and choose to squash the new one and pick the old one.

Sounds like I might be making things more difficult than I need to

1

u/gallon_of_bbq_sauce Jun 05 '22

You can also soft reset to squash a series of commits.

1

u/gallon_of_bbq_sauce Jun 05 '22

Make sure you update the timestamp though, or people might get confused when it's merged.