Not so popular git commands
The content here is under the Attribution 4.0 International (CC BY 4.0) license
Recently I’ve experienced a scenario that made my git skill in check, I was wondering if I could see the files that changed for a list of commits. From that, I tried to expand some questions around git. The goal here is to share a few git commands that are not popular like commit, push or rebase.
Are you not familiar with git yet? Have a look at the intro I made here.
What has changed?
Recently I came across this command that depicts what has been done by commit, renaming, deleting or adding files. It was quite a surprise for me as I had never heard about this option.
the output would be something like:
commit 7567155a8b62c9d8208c2f9b5d86a5026fb780b5 (HEAD -> master, origin/master, origin/HEAD) Author: marabesi <[email protected]> Date: Mon Nov 22 19:27:53 2021 -0300 refactor: renames stub to github.commits.json :100644 100644 33de7d1 f9ff071 M setupTest.js :100644 100644 85c2b71 85c2b71 R100 stubs/githuapi.json stubs/github.commits.json commit 10d8a8e748e1b28aaaa08d7ad674a85f30f877ae Author: marabesi <[email protected]> Date: Mon Nov 22 19:27:01 2021 -0300 refactor: moves github api stubs under stubs folder :100644 100644 ceb6b95 33de7d1 M setupTest.js :100644 100644 85c2b71 85c2b71 R100 src/githuapi.json stubs/githuapi.json :100644 100644 0967ef4 0967ef4 R100 src/github.empty.languages.json stubs/github.empty.languages.json :100644 100644 dc1751b dc1751b R100 src/github.empty.topics.json stubs/github.empty.topics.json :100644 100644 bbf13c7 bbf13c7 R100 src/github.languages.json stubs/github.languages.json :100644 100644 2af19a8 2af19a8 R100 src/github.topics.json stubs/github.topics.json
Commit add iterativo
git add -i
Merge and squash
Github by default offers to strategies to merge code into branches, rebase and squashing. While rebase in my experience is a command a bit more spread squashing via command line is not that popular - often I go to github and open a merge request just for that feature.
TO this end, we will still use rebase, but the strategy is different1:
- git rebase -i main
- In the list of commits, leave the first one as it is
- For the second onwards write s for squash
Filter commits by date
git log --after="2021-06-01" --until="2021-06-30"
Search in commits
git log --grep "my text here"
A few comments on gist around squashing: https://gist.github.com/aortbals/2aeb557bf127dd7ae88ea63da93479fc ↩