Git常用命令合集(日常整理)

    xiaoxiao2025-07-30  13

    远程分支强制覆盖本地分支(超级常用)

    置顶是因为我自己用了无数遍呀!!

    git fetch --all git reset --hard origin/your branch name git pull

    快捷提交

    git commit -a -m 'this is my commit'

    等价于

    git add . git commit -m 'your commit'

    命令简写(mac环境,windows没试)

    命令行输入:

    alias

    会列出所有git相关的缩写,当然也可以自己配。 常用的也就几个:

    切换指定分支: gco branch_name 切换到master分支: gcm 查看分支: gb 查看修改: gd 拉代码: gl

    新建没有parent的新分支

    git checkout --orphan branch-name

    Git 代码量

    git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done

    Git 命令提示:perl: warning: Setting locale failed.

    vim ~/.zshrc # Setting for the new UTF-8 terminal support in Lion LC_CTYPE=en_US.UTF-8 LC_ALL=en_US.UTF-8 source ~/.zshrc 重启iTerm

    merge某个或几个commit

    有些特殊情况不能直接merge(一个分支上同时有你和别人的commit),但是你的commit需要上线了。

    查找要merge的commitId gco old_branch git log

    commit 1534c530522982a6ff050ac420b300ae4364474e Author: lidoudou <lidoudou@csdn.com> Date: Sat Apr 27 17:15:14 2019 +0800 update kafka setting

    切换到目标分支,pick目标commit gco new_branch git cherr-pick 1534c530522 // commitId 正常的话现在可以看到new_branch上有了commitId不同,但是标识名相同的记录。当然也会出现意外——代码冲突了,按一般的冲突一样fix就OK了。
    最新回复(0)