pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit 5beab3d5ca54812d1f920f0b3a5113471c5367b5
parent fe863c83f71d7b4371a2a54fe23bc0b45f6bb316
Author: pyratebeard <root@pyratebeard.net>
Date:   Tue, 11 Jun 2024 11:25:23 +0100

Merge branch 'up_git_stream'

Diffstat:
Aentry/20240611-up_git_stream.md | 31+++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)

diff --git a/entry/20240611-up_git_stream.md b/entry/20240611-up_git_stream.md @@ -0,0 +1,31 @@ +Unlike most people (I imagine) I rarely, if ever, run `git pull` when refreshing my local Git repositories. + +Instead, over the years I have grown accustomed to running `git fetch` and `git merge` separately (a `pull` does both of these in one command). + +The reason for this is so that I can review the log and any changes before merging the remote code into my local repo. + +I would try to remember to run `git log` after fetching the remote code, which by default would show the entire log history of the repo. Then I read about the dotted range notation and `@` construct for specifying [revisions][1] in Git. + +Using `@` on is own is equal to `HEAD`. Combine it in `git log` with `{upstream}` or `{u}` to only show commit logs for the upstream branch + +``` +git log @{u} +``` + +The two-dot notation is shorthand for all commits in a range. Therefore to show only the commits from the remote upstream that have yet to be merged in my local branch I would incant +``` +git log HEAD..@{u} +``` + +This can be made even easier by omitting `HEAD`, as leaving one end of the range blank defaults to `HEAD` +``` +git log ..@{u} +``` + +With this newfound knowledge I updated my [`gf` alias][2] to run both commands, automatically showing me the commits I have fetched and need to review +``` +alias gf="git fetch && git log ..@{u}" +``` + +[1]: https://www.git-scm.com/docs/gitrevisions +[2]: https://git.pyratebeard.net/dotfiles/file/zsh/.config/zsh/aliases.zsh.html#l91