赞
踩
对应的文件为~/.gitconfig or ~/.config/git/config
git config --global user.name test
git config --global user.email test@example.com
git config --list # 查看配置信息
[color]
diff = auto
status = auto
branch = auto
interactive = true
ui = true
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.co checkout
git config --global alias.pl pull --rebase
git config --global alias.lgp log -p
git config --global alias.a add
// ~/.gitconfig
[alias]
st = status
ci = commit
br = branch
co = checkout
pl = pull --rebase
lgp = log -p
a = add
fork操作达到的效果是创建了一个子仓。
相关命令如下:
git remote -v
git remote add upstream https://github.com/selfteaching/the-craft-of-selfteaching.git
git fetch upstream
git merge upstream/master
操作 | 命令 | 备注 |
---|---|---|
查看远程仓库地址 | git remote -v | |
修改远程仓库地址 | git remote set-url origin [url] | |
修改远程仓库地址 | git remote rm origin && git remote add origin [url] | |
修改远程仓库地址 | git pull origin master --allow-unrelated-histories |
操作 | 命令 | 备注 |
---|---|---|
查看分支 | git branch -a | |
新建本地分支 | git checkout -b newbranch | |
删除本地分支 | git branch -d newbranch | |
新建远程分支 | git checkout -b newbranch && git push origin newbranch:newbranch | |
删除远程分支 | git push origin --delete newbranch / git push origin :localbranch | 推送一个空的分支即相当于删除远程分支 |
切换分支 | git checkout newbranch | |
分支合并 | git merge newbranch | 将newbranch合并到当前分支 |
操作 | 命令 |
---|---|
查看tag列表 | git tag |
查看tag信息 | git show newtag |
新建本地tag | git tag -a newtag |
删除本地tag | git tag -d newtag |
新建远程tag | git push origin master --tags |
删除远程tag | git push origin master :refs/tags/newtag |
操作 | 命令 | 备注 |
---|---|---|
查看提交记录 | git log | 只能看到commit的记录 |
查看对分支的所有操作记录 | git reflog | commit/reset/rebase操作均能看到 |
查看未暂存修改(工作区相比分支的差异) | git diff filename | 只能查看还未add的修改差异 |
查看已暂存区修改(暂存区相比分支的差异) | git diff --staged/cached |
操作 | 命令 | 备注 |
---|---|---|
拉取代码 | git pull --rebase | |
本地提交 | git add && git commit | |
远程提交 | git push | |
commit 合并 | git rebase -i commitid && pick -> s | commitid不会被合并;至少留一个pick;git push -f提交 |
操作 | 命令 | 备注 |
---|---|---|
保存当前暂存区的修改 | git stash save “message” | 只保存暂存区和分支的差异 |
查看当前暂存区中的修改 | git stash list |
操作 | 命令 | 备注 |
---|---|---|
强制回退工作区/暂存区/分支 | git reset --hard commitid | 工作区/暂存区/分支均同步到commitid |
回退分支到暂存区 | git reset --soft commitid | 仅分支回退到暂存区,暂存区和工作区原有内容均保留 |
回退分支/暂存区到工作区 | git reset commitid / git reset --mixed commitid | 分支/暂存区(二者保持一致)均回退到工作区,工作区已有的内容保留 |
取消暂存区的文件 | git reset HEAD filename | 回退之后,工作区仍能看到该文件修改 |
撤销对文件修改 | git checkout – filename | 执行后,工作区没有对该文件的修改 |
删除工作区未添加的文件或目录 | git clean -df | 删除Untracked文件/目录 |
操作 | 命令 | 备注 |
---|---|---|
删除工作区文件 | rm filename | 该文件还未被tracked到git仓里,文件被彻底删除 |
删除分支文件 | git rm filename | 该文件在暂存区中未被修改,文件被彻底删除 |
删除暂存区文件 | git rm -f filename | 该文件在暂存区中已被修改,和分支中文件有差异,文件被彻底删除 |
只从git中删除文件,仍保留在工作区中 | git rm --cached filename | 该文件仍保留在工作区 |
操作 | 命令 | 备注 |
---|---|---|
重命名暂存区或分支中文件名 | git mv oldfilename newfilename = mv && git rm && git add |
操作 | 命令 | 备注 |
---|---|---|
回退到某一操作 | git reflog && git reset --soft/ git reset --mixed |
.gitignore文件
git log --author="name" --pretty=tformat: --numstat --since==2019-12-21 --until=2020-01-21 | awk '{ add += $1; subs += $2; loc += $1-$2} END {printf "added lines:%s, removed lines:%s, total lines:%s\n", add, subs, loc}' -
git log 参数说明: –author 指定作者 –stat 显示每次更新的文件修改统计信息,会列出具体文件列表 –shortstat 统计每个commit 的文件修改行数,包括增加,删除,但不列出文件列表: –numstat 统计每个commit 的文件修改行数,包括增加,删除,并列出文件列表: -p 选项展开显示每次提交的内容差异,用 -2 则仅显示最近的两次更新 例如:git log -p -2 –name-only 仅在提交信息后显示已修改的文件清单 –name-status 显示新增、修改、删除的文件清单 –abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符 –relative-date 使用较短的相对时间显示(比如,“2 weeks ago”) –graph 显示 ASCII 图形表示的分支合并历史 –pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式) 例如: git log --pretty=oneline ; git log --pretty=short ; git log --pretty=full ; git log --pretty=fuller –pretty=tformat: 可以定制要显示的记录格式,这样的输出便于后期编程提取分析 例如:git log --pretty=format:""%h - %an, %ar : %s"" 下面列出了常用的格式占位符写法及其代表的意义。 选项 说明 %H 提交对象(commit)的完整哈希字串 %h 提交对象的简短哈希字串 %T 树对象(tree)的完整哈希字串 %t 树对象的简短哈希字串 %P 父对象(parent)的完整哈希字串 %p 父对象的简短哈希字串 %an 作者(author)的名字 %ae 作者的电子邮件地址 %ad 作者修订日期(可以用 -date= 选项定制格式) %ar 作者修订日期,按多久以前的方式显示 %cn 提交者(committer)的名字 %ce 提交者的电子邮件地址 %cd 提交日期 %cr 提交日期,按多久以前的方式显示 %s 提交说明 –since 限制显示输出的范围, 例如: git log --since=2.weeks 显示最近两周的提交 选项 说明 -(n) 仅显示最近的 n 条提交 –since, --after 仅显示指定时间之后的提交。 –until, --before 仅显示指定时间之前的提交。 –author 仅显示指定作者相关的提交。 –committer 仅显示指定提交者相关的提交。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。