使用
git clone
和git init
会生成.git
目录, 添加--bare
选项, 那么本身就是.git
目录, 没有checkout出任何文件..git
目录保存元数据和对象数据库.
下级配置会覆盖上级配置
git config –list –show-origin
git config –global user.name “” git config –global user.email “” git config –global core.editor “” # 默认会找$EDITOR 设置 git config –global merge.tool “”
git help
Untracked
, 未加入版本控制Staged
, 使用git restore --staged <file>...
撤消操作Committed
Modified
, 使用git restore <file>...
撤消操作#
开头的行都会被Git忽略./
说明要忽略的是目录.!
取反.git clone <url> <dirname>
git add <filename>
git add --all
git status
git status -s
git diff
git diff --staged(=cached, 1.6.1) 比较暂存区与git目录中文件
git commit -v -m <msg>
git commit --amend
git commit -a -m <msg>
git rm 取消文件跟踪
git rm --cached 只删除暂存区
git mv 移动文件
git log
-p 显示差异, -n 显示最新的n条 git log -p -2
–stat 显示简略统计 git log –stat
oneline, format git log –pretty=?
–graph 前面显示标识 git log –graph
git log --since, --after
git log --until, --before
–decorate 查看各个分支当前所指的对象 git log –oneline –decorate
会输出你的提交历史、各个分支的指向以及项目的分支分叉情况 git log –oneline –decorate –graph –all
git reset HEAD <file>...
git checkout -- <file>...
git remote
git remote -v 显示运程库地址
git remote add [shortname] [url] 添加远程库
git remote set-url [shortname] [url] 设置远程库
git remote show [shortname] 显示远程库信息
git fetch [shortname] 抓取仓库数据, 但不合并
git push origin master 推送master分支到origin远程库中
git pull = git fetch + git merge
git remote rename 远程库重命名
git remote rm 删除远程库
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
不会变化的分支 , 是个指向特定提交对象的引用.
含附注标签, 是存储在仓库中的一个独立对象, 有自身的校验和信息
git tag 不带参数为搜索所有
-l 搜索模式
-a
默认不会push标签信息, 需要显示的提交
git push origin <tag_name>
git push origin --tags 一次推送所有标签
创建本地分支 git branch
切换本地分支 git checkout
git switch
新建一个分支, 并切换 git checkout -b
当前分支与指定分支合并 git merge
删除本地分支 git branch -d
合并工具 git mergetool
查看当前分支 git branch
查看最后一次提交 git branch -v
–merged 与 –no-merged 显示已经合并 或没有合并的分支 git branch –merged
显式地获得远程引用的完整列表 git ls-remote
获得远程分支的更多信息 git remote show
<remote>/<branch>
抓取运程库最新数据, 不合并到本地 git fetch
当前分支推送到origin运程库的 serverfix分支 git push origin serverfix
合并运程分支 git merge origin/serverfix
以运程分支为基点, 创建新分支并切换 git checkout -b serverfix origin/serverfix
当前分支跟踪运程分支 git checkout –track origin/serverfix
设置当前分支的上游分支 git branch -u origin/serverfix git branch –set-upstream-to origin/serverfix
删除运程分支 git push origin –delete serverfix
推着并创建运程分支 git push –set-upstream origin
以master为底, 创建主题分支 git branch sc/ruby_client master git checkout -b sc/ruby_client master
contrib有但master没有 git log contrib –not master
git log master..contrib
找出基底 git merge-base contrib master
git diff $(git merge-base contrib master)
挑拣 git cherry-pick e43a6
rerere, 简化合并 git config –global rerere.enabled true
生成一个构建号 git describe master
某个分支指向哪个特定的 SHA-1 git rev-parse topic1
查看引用日志 git reflog
git show HEAD@{5}
git show master@{yesterday}
git log -g master
git show HEAD^
git show d921970^
git show HEAD~~~
git show HEAD~3
双点 查看 experiment 分支中还有哪些提交尚未被合并入 master 分支 git log master..experiment git log origin/master..HEAD
多点 git log refA..refB git log ^refA refB git log refB –not refA
三点 想看 master 或者 experiment 中包含的但不是两者共有的提交 git log master…experiment
显示每个提交到底处于哪一侧的分支 git log –left-right master…experiment
交互式暂存 git add -i/–interactive
git 调试 git blame
git 子模块 git submodule add https://github.com/chaconinc/DbConnector git submodule init git submodule update git clone –recurse-submodules
git plumbing vs porcelain git hash-object git cat-file -p git update-index git write-tree git read-tree git commit-tree
git update-ref
git symbolic-ref
git clean
贮藏工作 git stash git stash push 贮藏查看 git stash list
贮藏应用 git stash apply git stash apply stash@{2} git stash apply –index
不仅要贮藏所有已暂存的内容,同时还要将它们保留在索引中 git stash –keep-index
从贮藏创建一个分支 git stash branch testchanges
git diff > commit.patch
git diff 3da71ca35 8b5100cdcd > commit.patch
git diff --cached > commit.patch
git apply --check commit.patch
新
git format-patch
git send-email
git am
三方合并 git am -3
git rebase master
以service为底, rebase master和client git rebase –onto master server client
git submodule init
git submodule update
git remote -v
// 添加运程地址
git remote add origin http://git.XXXX.com/XXX/XXX.git/
// 修改运程地址
git remote set-url origin http://git.XXXX.com/XXX/XXX.git/
git tag -s v1.5 -m 'my signed 1.5 tag'
gpg --list-keys
gpg -a --export F721C45A | git hash-object -w --stdin
git tag -a maintainer-pgp-pub 659ef797d181633c87ec71ac3f9ba29fe5775b92
git show maintainer-pgp-pub | gpg --import
git archive master --prefix='project/' --format=zip > `git describe master`.zip
git archive master --prefix='project/' | gzip > `git describe master`.tar.gz
git shortlog --no-merges master --not v1.0.1
临时切换, 或以原始提交为基底创建分支 git checkout 0d1d7fc32 git checkout -b old-state 0d1d7fc32
硬删除未push提交 git stash git reset –hard 0d1d7fc32 git stash pop
git revert --no-commit 0766c053..HEAD
git revert --no-edit 0766c053..HEAD
git commit
# Resets index to former commit; replace '56e05fced' with your commit code
git reset 56e05fced
# Moves pointer back to previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
# Updates working copy to reflect the new commit
git reset --hard
# Push your changes to respective branch
git push -f
# 修改最后一次提交
git commit --amend
# 修改多个提交信息 重新排序提交 拆分提交
git rebase -i HEAD~3
# 通过脚本的方式改写大量提交
git filter-branch --tree-filter 'rm -f passwords.txt' HEAD
cd .repo/manifests
git branch -a
repo init -b <branch-name>
repo sync // 如果不需要与服务器数据一致, 可以不运行这步
repo start <branch-name> --all
repo branches // 查看切换结果
RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly before end of the underlying stream
5785 bytes of body are still expected
git config --global http.version HTTP/1.1
git config --global http.postBuffer 524288000
and have 365207 and 1 different commits each, respectively.
hint: Pulling without specifying how to reconcile divergent branches is hint: discouraged. You can squelch this message by running one of the following hint: commands sometime before your next pull:
git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only
git log HEAD..origin/master
git pull --rebase origin/master
git checkout Git 2.23 (August 2019)时拆分为两个命令:
1. git switch: 切换分支和创建新分支
2. git restore: 恢复已修改文件 = git checkout -- <file>...
.git/hooks
husky
commitlit
丢弃修改
git reset --hard HEAD^
git push origin master -f
创建一个commit 撤回上一个commit
git revert HEAD
git push origin master
切换branch及commit
git checkout <brach>
git checkout <commit>
git switch -c <brachname>