Mistakes! These are not a necessity in software development. But they always find a way to taint the beauty of software development.
Let's make pe...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
For 17 I would instead almost always recommend making a new commit on HEAD and then using rebase with the fixup verb to reorder and join the commits. This is for the simple reasons that it:
Similarly, I would avoid the restore command, instead using checkout and reset where appropriate.
Really, a reflog entry appears for each state at begin and end of each rebase, so they at least can be recovered.
That's why, an opposite, a file could be easily edited with the edited commit but not later.
restore
is a new command which just unifies multiple use cases for formercheckout
,branch
andreset
under a convenient common name. It hasn't added new functionality. To userestore
or older variants is still just a matter of taste.Well I think it is a bit of work having to reorder the commits so as to use the fixup action verb.
Then regarding the restore command, it was built for the restoring purpose in mind unlike the checkout command which is like a know it all command
Just as a side note, if you need to reorder and then fixup, you can instead just squash and then rewrite the commit message appropriately. Squash itself puts you in a commit "screen" anyways, so you can easily use the commit message you want.
A good intro, just a few notes:
For commands like
restore
, it is useful to separate paths from options with '--', e.g.git restore -s <commit_id> -- <path1> <path2>
. Shell completion relies on it.For recipe 3, if not to add
-m
, this opens editor. In a case of multiline commit message (typical for a complex project) this is much handier.Recipe 9: it's useful to note exceptions to cleaning, like:
git clean -dfx -e .vscode
.For recipe 11:
git log
works with commit ids as well, so,git log -p <id>
may suggest what was the branch to restore. Anyway, well, good messages are useful... but I'm regularly encountering the same commit sequence over different branches.Good notes👍. For recipe 9, I am curious why would I add the
-x
and then manually add-e
. Looks like a lot of workThis is the case build artifacts (all of them - object files, libraries, autogenerated sources, etc.) are present in the same directory as the working copy. Normally, they are all in .gitignore. Heavy cleaning from build results require deleting all of them. But, if IDE and other locals aren't a level upper, they are to be saved from deletion.
I have some added suggestions to complement what you have.
Use git switch instead of git checkout.
Rather than just dropping changes with a reset, switch into a new branch, commit, then switch out. This ensures if nothing else you'll have a reflog for a bit.
$ git commit --fixup
Or search a commit message instead of hash
$ git commit --fixup :/msg
Good overview of the different options at your disposal! Thank you very much for the article.
I just want to add that not all methods will remove your data from the repository. In normal circumstances that is exactly what you want. However, if you accidentally committed a password for example, this is something to look out for. In that situation it can make sence to revert your commit by rewriting history, but this will only make sence if you have not yet commited your code to the remote repo. If that is the case, you are better off considering your password compromised and start changing your password.
Changing your password is a good security precaution at personal level. I agree👍.
A very very nice beginner friendly list. Tnx!!!
Cheers
Welcome @igormihacic
Oh that's a nice overview, thanks!
Welcome Anja, I'll be having something for you again in this platform
Nice article
This is so helpful for a beginner, thank you!
Thanks! I'm grateful you found this useful
This is the first dev post I'm bookmarking. It's so resourceful.
Thanks
Thanks for sharing !
Welcome again on the next one
Hush! that was something I need to save and refer later.
That's awesome blog post. Helped me and saved my time.
I am glad i helped you increase your productivity👍