I'm quite sure all of these happened to you at least once:
You committed a change with the wrong message (typo, wrong tense, etc.)
You committed ...
For further actions, you may consider blocking this person and/or reporting abuse
I didn't know about
-amend
. Now I wonder how many commits I could have prevented with this knowledge.For example, I recently forgot to update the README of a project after adding a feature, so I did a second commit for that. From now on I'll be able to prevent this.
Thank you!
Nice to know! i always use rebase for that case
Exactly that! It's the perfect usecase for
amend
:DEnjoy ;)
As a beginner web developer, I find this "git better" series very useful :)
But I would like to add an experience to point 2 of this article.
I didn't know about
--amend
.It came at the right time, so I tried it.
I was stuck because when the editor opened I couldn't figure out how it worked.
I searched for
amend
online and found this solution:git commit --amend -m "change commit text"
It worked easier for me.
Nevertheless, I look forward to more of your articles because they are very useful for me.
Thank you!
Thanks for the comment! :)
Regardless of the
--amend
flag, if you do not use-m
, git will open your default text editor to insert a commit message.So yeah, to make it in one step you can use both
--amend
and-m "message"
and you can skip the step with the text editor.You're right, I could have just used both in the same command to make it easier :)
Thank you for this article.
I learnt new things here.
I also use rebase and Squash in some cases.
I am working across several machines and I was trying to find a way to share a stash with remote. It is in order to continue working from home.
5 PM → Traffic Jam Fun Time
Likely 5:30/6PM - Home Switch Home... I meant PC.
I did look for an option on StackOverflow but did not find anything that is quick and simple.
When I realise it's 2 to 5 PM, all I'd want to do is prepare to leave.
Basically I just commit with any commit message.
Then I work on my content from another machine and I squash the missing changes.
It works perfectly fro my purpose.
That's a smart idea, thanks for sharing it! :D
This is great, Leonardo. Thanks a lot! I didn't know about amend nor about reversing a hard reset. Useful indeed :-) 👍🏻😃
You might add a warning for the less experienced: These actions are about changing your own history. Do NOT change the history after you have shared it (in a shared branch of a shared repo), to prevent your peers from getting some nasty conflicts.
You want to do this stuff primarily to get your own history cleaned up before sharing your commits with others.
Yeah that's true, I'll add a line about that. If commits have already been pushed, it's a whole another story :P
this helped me,
thanks
Thanks for sharing your feedback, it's great to hear someone found it helpful :D
tks
i like these kind of articles; tips that should be easy and daily practice; but is something lots of people might never know about due to other work arounds
Thank you for the feedback! :)
I'll probably do more articles like this one in the future then, I also like reading these kind of tips that are usually simple but not necessarily known by everyone :D
Very helpful article. Thanks for sharing
Thank you for the feedback! :)
I see articles on git are usually well appreciated, I'll probably write more :D
Great article, but i think this can be avoid with conventional-commit?
Thanks for the comment :)
I'm not sure how... I mean, even with conventional-commit, if you forget to add a file or write a typo in the commit message, you might want to go back :)
Another example, if you did a commit but you later realize you didn't want to commit at all.
Or am I missing something here?
Conventional commit works to set a standard for the commits, but in the case that you are mentioning, it makes sense to use the amend, thanks for the response.