깃 alias

2021. 11. 16. 15:14개발

반응형

개인 저장용



종립님의 깃 단축어를 참고하여 내게 맞게 수정한 것

(출처 : https://johngrib.github.io/wiki/git-alias/)

 

코드 gits ( https://gist.github.com/yousung/515eeec8268544056c1a5664885e754e )

[alias]
    alias-basic = "!#----------------------------------------------------------;\n\
        git alias | head -7"
    ci = commit
    co = checkout
    sw = switch
    re = restore
    s = status -s
    assume   = update-index --assume-unchanged
    assumed  = "!git ls-files -v | grep ^h | cut -c 3-"
    unassume = update-index --no-assume-unchanged

    blist = "!git branch | grep -v '^\\*'"
    blist-merged = "!git branch --merged | grep -v '^\\*\\|\\<master$'"
    bclean = "!# current branch delete.; \n\
        f() { \
            branch=`git b0`; \
            git checkout master; \
            read -p \"Delete local branch $branch? [y|n] \" -r; \
            REPLY=${REPLY:-"n"}; \
            if [ $REPLY = \"y\" ]; then \
                git branch -D $branch; \
            fi; \
            read -p \"Delete origin branch $branch? [y|n] \" -r; \
            REPLY=${REPLY:-"n"}; \
            if [ $REPLY = \"y\" ]; then \
                git push origin --delete $branch; \
            fi; \
        }; f"
    alias-log = "!#----------------------------------------------------------;\n\
        git alias | egrep 'log|commit-'"
    commit-select = "!# Select a commit hash from log graph.;\n\
        git l \
        | fzf -m --ansi --layout=reverse --preview=\"echo {} | sed 's/^[*| ]*//g' | cut -d' ' -f1 | xargs git show --color=always \" \
        | sed 's/^[*| ]*//g' | cut -d' ' -f1"
    c-s = "!git commit-select"
    commit-copy = "!# Select & copy a commit hash from log graph.;\n\
        git commit-select | pbcopy && echo Copied : `pbpaste`;"
    c-c = "!git commit-copy"
    l = "log \
        --color --graph --decorate \
        --date=format:'%Y-%m-%d' \
        --abbrev-commit \
        --pretty=format:'%C(red)%h%C(auto)%d %s %C(green)(%cr)%C(bold blue) %an'"
    ll = "log \
        --color --graph --decorate \
        --date=format:'%Y-%m-%d' \
        --abbrev-commit \
        --all \
        --pretty=format:'%C(red)%h%C(auto)%d %s %C(green)(%cr)%C(bold blue) %an'"
    ranking = "!# List commit counts of contributors;\n\
        git shortlog -sn"
    alias-branch = "!#----------------------------------------------------------;\n\
        git alias | egrep '[bB]ranch'"
    b0 = "!# Print current branch.;\n\
        git branch | awk '/^\\*/{print $2}'"
    back = "!# Back up current branch.;\n\
        echo created new branch: backup-`git b0`;\
        git branch backup-`git b0`"
    done = "!git branch --merged | grep -v '^\\*\\|\\<master$'"
    bb = "!# Branch tools. Type 'git bb help'.;\n\
        f() { \n\
            if [ $# = 0 ]; then \
                git branch-select | xargs git checkout; \
            elif [ $1 = 'help' ]; then \
                echo 'git bb           : Select and checkout branch'; \
                echo 'git bb c, clean  : Clean all merged branches'; \
                echo 'git bb d, D      : Delete seleted branches(D: force)'; \
                echo 'git bb l, list   : List branches excluding the current branch'; \
                echo 'git bb m, merged : List merged branches excluding the current and master branches'; \
            elif [ $1 = 'd' -o $1 = 'D' ]; then \
                git branch -$1 $(git bb list | fzf -m | awk '{print $2}'); \
            elif [ $1 = 'clean' -o $1 = 'c' ]; then \
                git branch-clean; \
            elif [ $1 = 'list' -o $1 = 'l' ]; then \
                git branch-list; \
            elif [ $1 = 'merged' -o $1 = 'm' ]; then \
                git branch-merged; \
            elif [ $1 = 'select' -o $1 = 's' ]; then \
                git branch-select; \
            else \
                git bb help; \
            fi; \
        }; f"
    branch-clean = "!# Search and delete merged branches.;\n\
        curr_hash=`git show -s | head -1 | cut -d ' ' -f2`; \
        for branch in `find .git/refs -type f | fzf --ansi -m --preview=\"cat {} | xargs git l\"` ; do \
            hash=`cat $branch`; \
            if [ $hash = $curr_hash ]; then \
                continue; \
            fi; \
            git ll | egrep $hash -C 1; \
            read -p \"Delete $branch? [y|n] \" -r; \
            REPLY=${REPLY:-"n"}; \
            if [ $REPLY = \"y\" ]; then \
                rm $branch; \
                echo \"\\033[32m$branch \\033[0mhas been\\033[31m deleted\\033[0m.\n\"; \
            fi; \
        done"
    b-c = "!git branch-clean"
    branch-list = "!# List the branches.;\n\
        git for-each-ref --sort=-committerdate refs/heads --format='%(HEAD) %(refname:strip=2) | %(committerdate:relative) | %(authorname)' \
        | column -ts'|' \
        | sed 's/^ /./'"
    bl = "!git branch-list"
    branch-list-all = "!# List all branches.;\n\
        for branch in `git branch -r --merged | grep -v HEAD`; do echo `git show --format=\"%ci ; %cr ; %an ;\" $branch | head -n 1` $branch; done | sort -r | column -ts';'"
    bla = "!git branch-list-all"
    branch-select = "!# Select a branch.;\n\
        f() { \
            _height=$(stty size | awk '{print $1}');\
            git branch-list | fzf --preview \"git l {2} | head -n $_height\" | awk '{print $2}'; \
        }; f"
    b-s = "!git branch-select"
    gm = "!git pull --rebase origin master"
    ch = "!# Branch tools. Same with bb.;\n\
        git bb $1"
    sync = "!# Sync with a branch with the same name in the remote repo.;\n\
        git pull --rebase origin `git b0`;"
    update = "!# Synchronize the contents of local files with the repository;\n\
        branch=`git b-s`; \
        if ! [ -z $branch ]; then \
            git pull --rebase origin $branch; \
        fi"
    alias-stage = "!#----------------------------------------------------------;\n\
        git alias | egrep '(add|diff|stage)' -i"
    a = "!# Select files and Add them.;\n\
        git diff-select | xargs git add"
    a-c = "!# Add, Commit.;\n\
        git a; git commit"
    diff-info = "!# Print diff report.;\n\
        fileA=/tmp/git-s-$(uuidgen); \
        fileB=/tmp/git-diff-$(uuidgen); \
        git s | awk '{print $2,$1}' > $fileA; \
        git diff --numstat | awk '{print $3,$1,$2}' > $fileB; \
        join -t' ' -a 1 $fileA $fileB | awk '{print $2, \"(+\"$3 \",-\"$4\")\", $1}' | sed 's/(+,-)/./; s/^\\([^?]\\) *\\./\\1 STAGED/' | column -t -s' ' ; \
        rm -f $fileA $fileB; \
    "
    diff-select = "!# Select changed files to add them.;\n\
        f() { \
            git diff-info \
            | egrep -v '[^?] *STAGED ' \
            | fzf -m --header \"$(git diff --shortstat)\" --preview \
                \"if [[ {1} == '??' ]]; then bat {3}; else git diff --color=always {3}; fi\" \
            | awk '{print $3}'; \
        }; f"
    diff-unselect = "!# Select staged files to unstage them.;\n\
        f() { \
            git diff-info \
            | egrep '[^?] *STAGED ' \
            | fzf -m --header \"$(git diff --shortstat)\" --preview \
                \"if [[ {1} == '??' ]]; then pygmentize {3}; else git diff --color=always --cached {3}; fi\" \
            | awk '{print $3}'; \
        }; f"
    unstage = "!# Select staged files and Unstage them.;\n\
        git diff-unselect | xargs git reset HEAD"
    alias-stash = "!#----------------------------------------------------------;\n\
        git alias | grep stash"
    stash-apply = "!# Select a stash item and Apply it.;\n\
        git stash-op apply"
    s-a = "!git stash-apply"
    stash-drop= "!# Select the stash items and Drop them.;\n\
        for sid in $(git stash-select -m) ; do \
            git stash drop $sid; \
        done;"
    s-d = "!git stash-drop"
    stash-list = "!# List stash items.;\n\
        git stash list --pretty=format:\"%C(red)%gd%C(reset) %C(green)(%cr) %C(reset)%s\""
    s-l = "!git stash-list"
    stash-pop= "!# Select a stash item and Pop it.;\n\
        git stash-op pop"
    s-p = "!git stash-pop"
    stash-save = "!# Save changes into the stash stack.;\n \
        git diff-info; \
        read -p \"save message: \" msg; \
        git stash save \"$msg\""
    s-s = "!git stash-save"
    stash-select = "!# Select stash item(s).;\n\
        f() { \
            git stash-list \
            | fzf --ansi $1 --preview \"git stash show -p {1} --color=always\" \
            | cut -d' ' -f1; \
        }; f"
    stash-op = "!#A private stash tool.;\nf() { git stash-select | xargs git stash $1; }; f"
    tag-refresh = "!# Re reference tag.;\n \
        f() { \
            _height=$(stty size | awk '{print $1}');\
            tag_name=`git tag | fzf --preview=\"git l {1} | head -n $_height\" `; \
            echo $tag_name; \
            git tag -d $tag_name; \
            git tag $tag_name; \
        }; f"
    alias-alias = "!#----------------------------------------------------------;\n\
        git alias | grep alias"
    alias = "!# Prints all aliases.;\n\
        git config --list | egrep '^alias.+' | sed -e 's/^alias\\.//' | sed -e 's/^[^=]*=/\\'$'\\033[31m&\\033[(B\\033[m/' | column -t -s'=' | sed 's/!#* *//; s/;$//' | cut -c1-85"
    alias-doctor = "!# Check the dependency tools.;\n\
    f() { \
        if [ $(which pygmentize | wc -l) -lt 1 ]; then \
            echo 'Not found : Pygments(pygmentize)'; \
            echo '    see     : http://pygments.org/'; \
            echo '    install : pip3 install Pygments'; \
            echo '';\
        fi; \
        if [ $(which fzf | wc -l) -lt 1 ]; then \
            echo 'Not found : fzf'; \
            echo '    see          : https://github.com/junegunn/fzf#installation'; \
            echo '    install(Mac) : brew install fzf'; \
            echo '    install(git) : git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf'; \
            echo '                   ~/.fzf/install'; \
            echo '';\
        fi; \
    }; f"

 

'개발' 카테고리의 다른 글

깃 alias  (0) 2021.11.16
jetbrain(PHPSTORM) tool 테스트 코드 한글 method 밑줄 없애기  (0) 2021.04.14
The Tweleve Factor APP ( 12 Factor )  (0) 2021.03.19
nGrinder 란 무엇인가 ? (사용 후기)  (0) 2020.12.29
초기설정  (0) 2020.12.07
코딩, 어떤 언어로 시작하지?  (0) 2020.11.09

TAG