Git 是分布式的版本控制工具
可以直接在终端输入 git+回车,此时会出现提示信息
此时查看提示信息,列出了常用的 git 的可执行命令以及简介
usage: git [--version] [--help] [-C ] [-c =]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=] [--work-tree=] [--namespace=]
[]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
sparse-checkout Initialize and modify the sparse-checkout
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help ' or 'git help '
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
git config --list
输出
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
user.name=xxxx
user.email=****@xx.xx****
credential.helper=store
http.sslverify=false
git config [--global] user.name xxxx
git config [--global] user.email xxxx
一般 Git 使用的文本编辑器是 Vi 或者 Vim,也可设置为 Emacs
git config [--global] core.editor emacs
解决合并冲突时使用的差异分析工具,git 的差异分析工具选项包括:
kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge,和 opendiff 等合并工具的输出信息
git config [--global] merge.tool vimdiff
git config -e [--global]
输出:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://github.com/******/xxxx.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tQwoB3Mr-1682055699588)(2023-04-21-13-33-00.png)]
git init [path]// 初始化 [指定路径] git 仓库
git add *.c //新增.c结尾的文件为版本控制范围
git add README //新增README文件为版本控制范围
git commit -m '提交说明'
git clone <repo> [<directory>]
命令 | 说明 |
---|---|
git branch | 列出所有分支 |
git branch (branchname) | 创建分支命令 |
git checkout (branchname) | 切换分支命令 |
git merge [alias]/[branch] | 合并分支命令 |
git branch -d (branchname) | 删除分支命令 |
当你切换分支的时候,Git 会用该分支的最后提交的快照替换你的工作目录的内容, 所以多个分支不需要多个目录
命令 | 说明 |
---|---|
git remote | 查看用户远程库 |
git remote add [shortname] [url] | 添加远程仓库 |
git remote rm [别名] | 删除远程仓库 |
git fetch | 从远程库获取代码 |
git pull | 下载远程库代码并合并 |
git push [alias]/[branch] | 推送分支数据到远程仓库 |
命令 | 说明 |
---|---|
git log | 查看历史提交记录 |
git blame [file] | 以列表形式查看指定文件的历史修改记录 |
git log [attr]:
git log --before={3.weeks.ago}
git log --after={2010-04-18}
希望记住特别的提交快照,可以使用 git tag 打上标签
git tag -a <tagname> [-m "runoob.com标签"] [commitId]
git tag
git tag -d [tagname]
git show [tagname]
命令 | 说明 |
---|---|
git add . | 添加文件到暂存区 |
git commit | 将暂存区内容添加到版本库或本地仓库中 |
git status | 查看仓库当前状态 |
git diff | 比较文件的不同,即暂存区和工作区的差异。 |
git reset | 回退版本 |
git rm | 将文件从暂存区和工作区中删除 |
git mv | 移动或重命名工作区文件 |