Difference between revisions of "Git cheatsheet"

From Wasya Wiki
Jump to: navigation, search
Line 40: Line 40:
 
=== set globalgitignore ===
 
=== set globalgitignore ===
 
  git config --global core.excludesfile '~/.gitignore'
 
  git config --global core.excludesfile '~/.gitignore'
 +
 +
=== Allow empty commit ===
 +
git commit --allow-empty -m 'trigger build'

Revision as of 14:24, 10 December 2019

Git cheatsheet - nifty git usage example.

which commit does a blob belong to?

which.sh:

#!/bin/sh
obj_name="$1"
shift
git log "$@" --pretty=format:'%T %h %s' \
| while read tree commit subject ; do
    if git ls-tree -r $tree | grep -q "$obj_name" ; then
        echo $commit "$subject"
    fi
done
which.sh <blob>

show history for a file

git log --follow -p -- file

show one commit

git diff <commit>~ <commit>

check branch

git branch | grep -e "^*" | cut -d' ' -f 2

see most recent branch

git branch -a --sort=-committerdate
git branch -a --sort=committerdate

What's the latest commit in the branch?

git log -n 1 <branchname> --format=format:%ci

list conflicting files

git diff --name-only --diff-filter=U

set globalgitignore

git config --global core.excludesfile '~/.gitignore'

Allow empty commit

git commit --allow-empty -m 'trigger build'