24
loading...
This website collects cookies to deliver better user experience
git diff
and git log
can print large amounts of text to standard output and are hence paginated by default (using less
command under the hood), requiring user input for navigation and termination. To disable pagination and have Git display the entire output, we can just pass the --no-pager
flag to Git.git --no-pager log
.bashrc
(Linux) or .zshrc
(macOS), although I do not recommend doing this.export GIT_PAGER=""
git status
doesn't help since there are no hint commands displayed as would be before committing. In this situation, we can usegit restore --source=HEAD~ --staged -- <file>
git reset --soft HEAD~
git rev-parse HEAD
git shortlog
command can be used to aggregate commits by author and title. This is especially useful for release announcements. It even provides a summary of commits by count. $ git shortlog -sn
62 EKS Distro Bot
31 Abhay Krishna
29 EKS Distro PR Bot
27 Abhay Krishna Arunachalam
23 [REDACTED]
15 [REDACTED]
.
.
.
git add
ed, we need to amend the commit to include the new changes, but we probably want to retain the same commit message.git commit --amend --no-edit
git commit --amend -C HEAD
git config alias.cwa 'commit --amend --no-edit'
git log --oneline
git rebase -i HEAD~n # n is the depth from the previous step
git fetch upstream
git rebase upstream/main
git reflog
(read ref-log and not re-flog, though I get why one might think they can expect Git to co-operate by repeatedly flogging it for all the torture 😤).git reflog
gives you an entire history of all the changes and actions you made across all branches in the local repository. The entries in the log are called reference logs, and they record when the tips of branches and other references were updated in the local Git working tree. Each entry is marked with an index number which can be used to move forward and backward through history.reflog
has several use-cases such as retrieving lost/deleted commits, reverting breaking changes, identifying divergent paths, etc.-w
or --web
flag.git branch
can be opened on the default browser (configurable) usinggit help branch -w
git branch --help -w
git diff
and git show
in their raw form are great for displaying all the changes that are yet to be and have been committed, respectively. But in some cases, we may only require the names of files affected by a Git operation (for example, for scripting or filtering). We can directly obtain just the names by passing the following flags to the command.git diff --pretty="format:" --name-only
git show --pretty="format:" --name-only
git diff --staged --pretty="format:" --name-only
git show --pretty="format:" --name-only -- "*.py"