Test SSH connections over HTTPS
ssh -T git@github.com
To test if SSH over the HTTPS port is possible, run this SSH command:
ssh -T -p 443 git@ssh.github.com
https://git-scm.com/book/zh/v2/起步-获取帮助
https://www.git-scm.com/book/en/v2/Getting-Started-Getting-Help
Getting Help
If you ever need help while using Git, there are three equivalent ways to get the comprehensive manual page (manpage) help for any of the Git commands:
若你使用Git时需要获取帮助,有三种等价的方法可以找到Git命令的综合手册(manpage):
$ git help <verb>
$ git <verb> --help
$ man git-<verb>
[root@openvpn DevNet]# git help config
[root@openvpn DevNet]# git config --help
[root@openvpn DevNet]# man git-config
In addition, if you don’t need the full-blown manpage help, but just need a quick refresher on the available options for a Git command, you can ask for the more concise “help” output with the -h option, as in:
此外,如果你不需要全面的手册,只需要可用选项的快速参考,那么可以用-h选项获得更简明的“help”输出:
$ git add -h
[root@openvpn DevNet]# git add -h
usage: git add [<options>] [--] <pathspec>...
-n, --dry-run dry run
-v, --verbose be verbose
-i, --interactive interactive picking
-p, --patch select hunks interactively
-e, --edit edit current diff and apply
-f, --force allow adding otherwise ignored files
-u, --update update tracked files
--renormalize renormalize EOL of tracked files (implies -u)
-N, --intent-to-add record only the fact that the path will be added later
-A, --all add changes from all tracked and untracked files
--ignore-removal ignore paths removed in the working tree (same as --no-all)
--refresh don't add, only refresh the index
--ignore-errors just skip files which cannot be added because of errors
--ignore-missing check if - even missing - files are ignored in dry run
--chmod (+|-)x override the executable bit of the listed files
--pathspec-from-file <file>
read pathspec from file
--pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character
[root@openvpn DevNet]#
https://git-scm.com/book/zh/v2/起步-初次运行-Git-前的配置
https://www.git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
安装完 Git 之后,要做的第一件事就是设置你的用户名和邮件地址。这一点很重要,因为每一个 Git 提交都会使用这些信息,它们会写入到你的每一次提交中,不可更改:
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
git remote上传到远程代码库:第一次上传
①初始化git版本库:git init
②添加文件到本地库:git add .
③提交文件到本地库:git commit -m "msg(提交日志)"
重要提示:②③可合并(git commit -am "")
④关联远程库:git remote add origin(可修改) branch_Name(为空时默认为main) url
关联之后可以用git remote -v 来检查是否关联成功
⑤一般情况需要先Pull一下:git pull origin main
一般情况下含有共同文件时需要执行 git merge origin/master --allow-unrelated-histories
这之后解决一下冲突
⑥Push到远程库:git push -u origin main
# git push <remote> <branch> # $ git push origin main
先在GitHub上创建某个repository,比如起名为DevNet:
①⋯or create a new repository on the command line
echo "# DevNet" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:rossnrachel/DevNet.git
git push -u origin main
②⋯or push an existing repository from the command line
git remote add origin git@github.com:rossnrachel/DevNet.git
git branch -M main
git push -u origin main
③⋯or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
/Users/ross/DevNet/Git/Git教程/01 Git快速入门.docx
/Users/ross/DevNet/Git/Git教程/01 Git使用教程详细.docx
cat ~/.gitconfig # --global的配置文件
cat .git/config # 当前repo的配置文件
git status # 查看工作区状态
git status -s|--short # 状态简览
git clone https://github.com/nornir-automation/nornir # 克隆现有的仓库,TCP443
git clone git:// # 使用git://协议,克隆现有的仓库?
git clone user@server:path/to/repo.git # 使用SSH协议,克隆现有的仓库,TCP22
例如: git clone git@github.com:nornir-automation/nornir.git # 使用SSH协议,克隆现有的仓库
git clone https://github.com/libgit2/libgit2 mylibgit # 将远程仓库libgit2克隆到本地,目录名为更改为mylibgit(自定义本地仓库名字/指定新的目录名)
https://git-scm.com/book/zh/v2/Git-基础-获取-Git-仓库
/* https://www.git-scm.com/docs/git-clone
The native transport (i.e. git:// URL) does no authentication and should be used with caution on unsecured networks.
The following syntaxes may be used with them:
ssh://[user@]host.xz[:port]/path/to/repo.git/
git://host.xz[:port]/path/to/repo.git/
http[s]://host.xz[:port]/path/to/repo.git/
ftp[s]://host.xz[:port]/path/to/repo.git/
An alternative scp-like syntax may also be used with the ssh protocol:
[user@]host.xz:path/to/repo.git/
*/
HEAD 是当前分支引用的指针,它总是指向该分支上的最后一次提交。 这表示 HEAD 将是下一次提交的父结点。 通常,理解 HEAD 的最简方式,就是将它看做 该分支上的最后一次提交 的快照。
git log # 查看提交日志
git log -n # 显示最后n次提交
git log --pretty=oneline -1 # 简化显示最后一次提交
git log --pretty=oneline --abbrev-commit # 查看历史提交信息
git log --graph --pretty=oneline --abbrev-commit # 查看分支合并情图 # 等价于git log --graph --oneline
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Or, if you want to see the lines that changed:
git lg -p # https://coderwall.com/p/euwpig/a-better-git-log
# (by @cervedin): I would suggest changing %cr to %ar as commit dates change when rebasing
https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History # Table 1. Useful specifiers for git log --pretty=format
https://git-scm.com/book/zh-tw/v2/Git-基礎-檢視提交的歷史記錄 # 表格 1. git log --pretty=format 實用選項
%H Commit hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author email
%ad Author date (format respects the --date=option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s Subject
You may be wondering what the difference is between author and committer. \
The author is the person who originally wrote the work, whereas the committer \
is the person who last applied the work. So, if you send in a patch to a project and \
one of the core members applies the patch, both of you get credit — you as the author, \
and the core member as the committer. We’ll cover this distinction a bit more in \
Distributed Git (https://git-scm.com/book/en/v2/ch00/ch05-distributed-git).
git log -p [-n] # 按补丁格式显示每个提交引入的差异
git log --stat # 显示每次提交的文件修改统计信息
git log -S function_name
git log --pretty=format:"%h - %an, %ar : %s" [--graph]
git log --pretty=format:"%h - %an, %ad : %s" [--graph]
git log --pretty=format:"%h - %an, %cd : %s" [--graph]
git log --pretty=format:"%h - %an, %cr : %s" [--graph]
git log --pretty=format:"%h %s" --graph
https://www.git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History
https://git-scm.com/book/zh/v2/Git-基础-查看提交历史
例子:如果要在Git源码库中查看 Junio Hamano 在2008年10月其间,除了合并提交之外的哪一个提交修改了测试文件,可以使用下面的命令:
git log --pretty=format:"%h - %s" --author="Junio C Hamno" --since="2008-10-01" --before="2008-11-01" --no-merges -- t/
用两个短划线(--)隔开之前的选项和后面限定的路径名。
隐藏合并提交:
按照你代码仓库的工作流程,记录中可能有为数不少的合并提交,它们所包含的信息通常并不多。 为了避免显示的合并提交弄乱历史记录,可以为 log 加上 --no-merges 选项。
git diff file # 是工作区(working dir)和暂存区(stage)的比较 (工作区的文件和add后的文件)
# 此命令比较的是工作目录中当前文件和暂存区域快照之间的差异,也就是修改之后还没有暂存起来的变化内容.
git diff --cached file # 是暂存区(stage)和分支(master)的比较 (add后的文件和commit后的文件) # 等价于git diff --staged file
# 这条命令将比对已暂存文件与最后一次提交的文件差异
git diff HEAD -- file # 是工作区和分支的比较
git difftool --tool-help # 查看你的系统支持哪些Git Diff插件
git reflog # 查看命令历史/commit_id
git reset --hard commit_id # 版本回退 # 危险操作
git reset --hard HEAD^ # 回退到上一个版本(HEAD表示当前版本) # 危险操作
git reset --hard HEAD^^ # 回退到上上个版本 # 危险操作
git reset --hard HEAD~100 # 回退到往上100个版本 # 危险操作
https://git-scm.com/book/zh/v2/ch00/_git_reset
https://git-scm.com/book/zh/v2/Git-工具-重置揭秘#_git_reset
https://git-scm.com/book/zh/v2/Git-基础-撤销操作
https://www.git-scm.com/book/en/v2/Git-Basics-Undoing-Things
git show 1d80c47 ssh-keygen.txt # 查看某个文件当前版本和上一个版本之间的差异
git blame FileName # 查看文件中每一行来自哪个版本
git-blame - Show what revision and author last modified each line of a file
丢弃工作区的修改(Old):
git checkout -- <file> # 丢弃工作区的修改 - 回到最近一次git commit或git add时的状态 # 危险操作
丢弃暂存区和工作区的修改,分两步(Old):
①git reset HEAD <file> # 把暂存区的修改撤销掉(unstage);不加文件名,那么可以回滚所有暂存区的文件 # use "git restore --staged <file>..." to unstage
②git checkout -- <file> # *表示通配符,表示回滚所有修改过后的文件 # use "git restore <file>..." to discard changes in working directory
git restore --staged <file> 等价于 git reset HEAD <file> # 作用一样
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
丢弃工作区的修改(New):
git restore <file>... # 丢弃工作区的修改 - 回到最近一次git commit或git add时的状态
丢弃暂存区和工作区的修改,分两步(New):
①git restore --staged <file> # 把暂存区的修改撤销掉(unstage);不加文件名,那么可以回滚所有暂存区的文件
②git restore <file>... # use "git restore <file>..." to discard changes in working directory
git commit -m "first commit"
git commit
git commit -v
git commit -a # 跳过使用暂存区域 # -a 选项,会自动把所有已经跟踪过的文件暂存起来一并提交,从而跳过git add步骤
git commit -a -m 'added new benchmarks'
https://www.git-scm.com/book/en/v2/Git-Branching-Branch-Management
git branch <branchname> # 创建分支
git branch # 查看分支;git branch命令会列出所有分支,当前分支前面会标一个*号
git branch -r # 只查看远程分支
git branch -a # 查看本地和远程分支;远程分支会用红色表示出来(如果你开了颜色支持的话)
git branch -v # 查看每一个分支的最后一次提交 # 下面两条命令的commit-id可以通过本命令获得
git branch --merge # 查看哪些分支已经合并到当前分支 # git branch --merge <branchname / commit-id> 查看哪些分支已经合并到指定分支
git branch --no-merged # 查看所有包含未合并工作的分支 # git branch --no-merge <branchname/ commit-id> 查看哪些分支尚未合并到指定分支
git branch -d <BranchName> # 删除分支
git branch -D <BranchName> # 强制删除分支,即使该分支没有合并(merge)也删除
git checkout <branchname> # 切换分支
git checkout -b <branchname> # 创建+切换分支 (常用)
git switch -c new-branch # 创建+切换分支 (From Git V2.23 onwards)
From Git version 2.23 onwards you can use git switch instead of git checkout to:
Switch to an existing branch: git switch testing-branch.
Create a new branch and switch to it: git switch -c new-branch. The -c flag stands for create, you can also use the full flag: --create.
Return to your previously checked out branch: git switch -.
git switch - # Return to your previously checked out branch
# Changing a branch name
# https://www.git-scm.com/book/en/v2/Git-Branching-Branch-Management
git branch --move bad-branch-name corrected-branch-name # Rename the branch locally
git push --set-upstream origin corrected-branch-name # Push it to let others see the corrected branch on the remote (GitHub, GitLab, other server)
git push origin --delete bad-branch-name # Delete the bad branch from the remote
#
# Changing the master branch name
git branch --move master main # Rename your local "master" branch into "main"
git push --set-upstream origin main # Push the new "main" branch to the remote. This makes the renamed branch available on the remote.
# Your local master branch is gone, as it’s replaced with the main branch. \
# The main branch is also available on the remote. But the remote still has a master branch. \
# Other collaborators will continue to use the master branch as the base of their work, until you make some further changes.
#
# Now you have a few more tasks in front of you to complete the transition:
## Any projects that depend on this one will need to update their code and/or configuration.
## Update any test-runner configuration files.
## Adjust build and release scripts.
## Redirect settings on your repo host for things like the repo’s default branch, merge rules, and other things that match branch names.
## Update references to the old branch in documentation.
## Close or merge any pull requests that target the old branch.
#
# After you’ve done all these tasks, and are certain the "main" branch performs just as the "master" branch, you can delete the master branch:
git push origin --delete master
合并分支及删除分支:
git merge <branchname> # 用于合并指定分支到当前分支。
git branch -d <branchname> # -d 表示delete
git stash # 保存工作现场
git stash list # 查看工作现场
git stash pop # 恢复工作现场
git branch -D <branchname> # 丢弃一个没有合并过的分支
# Git 支持两种标签: 轻量标签(lightweight)与附注标签(annotated).
附注标签: git tag -a v1.4 -m "my version 1.4"
轻量便签: git tag v1.4 # 创建轻量标签,不需要使用-a、-s或-m选项,只需要提供标签名字
git tag # 查看标签
git tag <tagname> <commit-id> # 新建一个标签;不加commit-id时,默认为HEAD
/*
# 针对某个Commit ID打标签
# 1、查看历史提交信息
$ git log --pretty=oneline --abbrev-commit
# 2、针对Commit ID打标签
$ git tag v1.1 f52c633
# 3、查看标签对应的信息
$ git show v1.1
# 4、创建带有说明的标签, -a 表示标签名, -m 表示说明性的文字
$ git tag -a 'v1.1' -m 'Version 1.0' f52c633
*/
git push origin <tagname> # 推送某个标签到远程仓库(默认状态下标签是不会进行推送的)
git push origin --tags # 推送所有标签到远程仓库
# 删除标签
git tag -d <tagname> # 删除掉你本地仓库上的标签
git push <remote> :refs/tags/<tagname> # 方法一:更新你的远程仓库;即先删除本地标签,再更新远程仓库
# git push origin :refs/tags/v1.4-lw
# 上面这种操作的含义是,将冒号前面的空值推送到远程标签名,从而高效地删除它.
git push origin --delete <tagname> # 方法二:更直观的删除远程标签的方式
git config --global color.ui true # 让Git显示颜色,这样配置以后文件名就会被标上颜色
git config --list --show-origin # You can view all of your settings and where they are coming from using this command.
[root@openvpn DevNet]# git config --list --show-origin # 查看所有的配置以及它们所在的文件
file:/root/.gitconfig user.name=rossnrachel
file:/root/.gitconfig user.email=417588889@qq.com
file:/root/.gitconfig alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
file:.git/config core.repositoryformatversion=0
file:.git/config core.filemode=true
file:.git/config core.bare=false
file:.git/config core.logallrefupdates=true
file:.git/config remote.origin.url=git@github.com:rossnrachel/DevNet
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config branch.main.remote=origin
file:.git/config branch.main.merge=refs/heads/main
[root@openvpn DevNet]#
[root@openvpn DevNet]# git config --list
user.name=rossnrachel
user.email=417588889@qq.com
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:rossnrachel/DevNet
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
[root@openvpn DevNet]#
[root@openvpn DevNet]# git config user.name
rossnrachel
[root@openvpn DevNet]# git config user.email
417588889@qq.com
[root@openvpn DevNet]#
由于 Git 会从多个文件中读取同一配置变量的不同值,因此你可能会在其中看到意料之外的值而不知道为什么. \
此时,你可以查询Git中该变量的"原始"值,它会告诉你哪一个配置文件最后设置了该值:
$ git config --show-origin rerere.autoUpdate
file:/home/johndoe/.gitconfig false
[root@openvpn DevNet]# git config --show-origin user.name
file:/root/.gitconfig rossnrachel
[root@openvpn DevNet]# git config --show-origin user.email
file:/root/.gitconfig 417588889@qq.com
[root@openvpn DevNet]#
配置别名举例:
git config --global alias.st status
git config --global alias.co checkout
/* https://git-scm.com/book/zh/v2/Git-基础-Git-别名
$ git config --global alias.unchange "reset HEAD"
$ git unchange Readme.txt
# 实际上执行的就是 git reset HEAD Readme.txt
原命令: git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
现命令: git lg
[root@openvpn ciscorepo]# cat ~/.gitconfig
[user]
name = rossnrachel
email = ********@********.********
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[root@openvpn ciscorepo]#
$ 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 config --global alias.unstage 'reset HEAD --'
这会使下面的两个命令等价:
$ git unstage fileA
$ git reset HEAD -- fileA
$ git config --global alias.last 'log -1 HEAD'
$ git last # 查看最后一次提交
Git只是简单地将别名替换为对应的命令.然而,你可能想要执行外部命令,而不是一个Git子命令. \
如果是那样的话,可以在命令前面加入"!"符号.如果你自己要写一些与Git仓库协作的工具的话, \
那会很有用.我们现在演示将git visual定义为gitk的别名:
$ git config --global alias.visual '!gitk'
*/
git查看远程仓库地址:
cisco@ubuntu:~/nxos-ansible$ git remote -v
origin https://github.com/jedelman8/nxos-ansible.git (fetch)
origin https://github.com/jedelman8/nxos-ansible.git (push)
cisco@ubuntu:~/nxos-ansible$
git remote show <remote> # 查看某一个远程仓库的更多信息(查看remote地址、远程分支、还有本地分支与之相对应关系等信息)
[root@openvpn DevNet]# git remote show origin
* remote origin
Fetch URL: git@github.com:rossnrachel/DevNet
Push URL: git@github.com:rossnrachel/DevNet
HEAD branch: main
Remote branches:
dev tracked
main tracked
Local branch configured for 'git pull':
main merges with remote main
Local refs configured for 'git push':
dev pushes to dev (up to date)
main pushes to main (fast-forwardable)
[root@openvpn DevNet]#
查看远程仓库已经不存在的分支,根据提示,删除那些远程仓库不存在的分支
git remote prune origin # 删除那些远程仓库不存在的分支
https://blog.csdn.net/weixin_36185028/article/details/93474944
远程仓库的重命名与移除 / Renaming and Removing Remotes
You can run git remote rename to change a remote’s shortname. For instance, if you want to rename pb to paul, you can do so with git remote rename:
$ git remote rename pb paul
$ git remote
origin
paul
It’s worth mentioning that this changes all your remote-tracking branch names too. What used to be referenced at pb/master is now at paul/master.
If you want to remove a remote for some reason - you've moved the server or are no longer using a particular mirror, or perhaps a contributor isn’t contributing anymore - you can either use git remote remove or git remote rm:
$ git remote remove paul
$ git remote
origin
Once you delete the reference to a remote this way, all remote-tracking branches and configuration settings associated with that remote are also deleted.
https://www.git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes
From git version 2.27 onwards, git pull will give a warning if the pull.rebase variable is not set. Git will keep warning you until you set the variable.
If you want the default behavior of git (fast-forward if possible, else create a merge commit): git config --global pull.rebase "false"
If you want to rebase when pulling: git config --global pull.rebase "true"
$ git pull
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
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
You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.
Already up to date.
$
Git Diff 的插件版本
在本书中,我们使用 git diff 来分析文件差异。 但是你也可以使用图形化的工具或外部 diff 工具来比较差异。 可以使用 git difftool 命令来调用 emerge 或 vimdiff 等软件(包括商业软件)输出 diff 的分析结果。 使用 git difftool --tool-help 命令来看你的系统支持哪些 Git Diff 插件。
所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。 星号(*)匹配零个或多个任意字符;[abc] 匹配任何一个列在方括号中的字符 (这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c); 问号(?)只匹配一个任意字符;如果在方括号中使用短划线分隔两个字符, 表示所有在这两个字符范围内的都可以匹配(比如 [0-9] 表示匹配所有 0 到 9 的数字)。 使用两个星号(**)表示匹配任意中间目录,比如 a/**/z 可以匹配 a/z 、 a/b/z 或 a/b/c/z 等。
[root@openvpn .git]# git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
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 <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
[root@openvpn .git]#
[root@openvpn .git]# git help -g
The Git concept guides are:
attributes Defining attributes per path
cli Git command-line interface and conventions
core-tutorial A Git core tutorial for developers
credentials Providing usernames and passwords to Git
cvs-migration Git for CVS users
diffcore Tweaking diff output
everyday A useful minimum set of commands for Everyday Git
faq Frequently asked questions about using Git
glossary A Git Glossary
hooks Hooks used by Git
ignore Specifies intentionally untracked files to ignore
modules Defining submodule properties
namespaces Git namespaces
remote-helpers Helper programs to interact with remote repositories
repository-layout Git Repository Layout
revisions Specifying revisions and ranges for Git
submodules Mounting one repository inside another
tutorial A tutorial introduction to Git
tutorial-2 A tutorial introduction to Git: part two
workflows An overview of recommended workflows with Git
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
[root@openvpn .git]#
[root@openvpn .git]# git help -a
See 'git help <command>' to read about a specific subcommand
Main Porcelain Commands
add Add file contents to the index
am Apply a series of patches from a mailbox
archive Create an archive of files from a named tree
bisect Use binary search to find the commit that introduced a bug
branch List, create, or delete branches
bundle Move objects and refs by archive
checkout Switch branches or restore working tree files
cherry-pick Apply the changes introduced by some existing commits
citool Graphical alternative to git-commit
clean Remove untracked files from the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
describe Give an object a human readable name based on an available ref
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
format-patch Prepare patches for e-mail submission
gc Cleanup unnecessary files and optimize the local repository
gitk The Git repository browser
grep Print lines matching a pattern
gui A portable graphical interface to Git
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
maintenance Run tasks to optimize Git repository data
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
notes Add or inspect object notes
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
range-diff Compare two commit ranges (e.g. two versions of a branch)
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
restore Restore working tree files
revert Revert some existing commits
rm Remove files from the working tree and from the index
shortlog Summarize 'git log' output
show Show various types of objects
sparse-checkout Initialize and modify the sparse-checkout
stash Stash the changes in a dirty working directory away
status Show the working tree status
submodule Initialize, update or inspect submodules
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
worktree Manage multiple working trees
Ancillary Commands / Manipulators
config Get and set repository or global options
fast-export Git data exporter
fast-import Backend for fast Git data importers
filter-branch Rewrite branches
mergetool Run merge conflict resolution tools to resolve merge conflicts
pack-refs Pack heads and tags for efficient repository access
prune Prune all unreachable objects from the object database
reflog Manage reflog information
remote Manage set of tracked repositories
repack Pack unpacked objects in a repository
replace Create, list, delete refs to replace objects
Ancillary Commands / Interrogators
annotate Annotate file lines with commit information
blame Show what revision and author last modified each line of a file
bugreport Collect information for user to file a bug report
count-objects Count unpacked number of objects and their disk consumption
difftool Show changes using common diff tools
fsck Verifies the connectivity and validity of the objects in the database
gitweb Git web interface (web frontend to Git repositories)
help Display help information about Git
instaweb Instantly browse your working repository in gitweb
merge-tree Show three-way merge without touching index
rerere Reuse recorded resolution of conflicted merges
show-branch Show branches and their commits
verify-commit Check the GPG signature of commits
verify-tag Check the GPG signature of tags
whatchanged Show logs with difference each commit introduces
Interacting with Others
archimport Import a GNU Arch repository into Git
cvsexportcommit Export a single commit to a CVS checkout
cvsimport Salvage your data out of another SCM people love to hate
cvsserver A CVS server emulator for Git
imap-send Send a collection of patches from stdin to an IMAP folder
p4 Import from and submit to Perforce repositories
quiltimport Applies a quilt patchset onto the current branch
request-pull Generates a summary of pending changes
send-email Send a collection of patches as emails
svn Bidirectional operation between a Subversion repository and Git
Low-level Commands / Manipulators
apply Apply a patch to files and/or to the index
checkout-index Copy files from the index to the working tree
commit-graph Write and verify Git commit-graph files
commit-tree Create a new commit object
hash-object Compute object ID and optionally creates a blob from a file
index-pack Build pack index file for an existing packed archive
merge-file Run a three-way file merge
merge-index Run a merge for files needing merging
mktag Creates a tag object
mktree Build a tree-object from ls-tree formatted text
multi-pack-index Write and verify multi-pack-indexes
pack-objects Create a packed archive of objects
prune-packed Remove extra objects that are already in pack files
read-tree Reads tree information into the index
symbolic-ref Read, modify and delete symbolic refs
unpack-objects Unpack objects from a packed archive
update-index Register file contents in the working tree to the index
update-ref Update the object name stored in a ref safely
write-tree Create a tree object from the current index
Low-level Commands / Interrogators
cat-file Provide content or type and size information for repository objects
cherry Find commits yet to be applied to upstream
diff-files Compares files in the working tree and the index
diff-index Compare a tree to the working tree or index
diff-tree Compares the content and mode of blobs found via two tree objects
for-each-ref Output information on each ref
get-tar-commit-id Extract commit ID from an archive created using git-archive
ls-files Show information about files in the index and the working tree
ls-remote List references in a remote repository
ls-tree List the contents of a tree object
merge-base Find as good common ancestors as possible for a merge
name-rev Find symbolic names for given revs
pack-redundant Find redundant pack files
rev-list Lists commit objects in reverse chronological order
rev-parse Pick out and massage parameters
show-index Show packed archive index
show-ref List references in a local repository
unpack-file Creates a temporary file with a blob's contents
var Show a Git logical variable
verify-pack Validate packed Git archive files
Low-level Commands / Syncing Repositories
daemon A really simple server for Git repositories
fetch-pack Receive missing objects from another repository
http-backend Server side implementation of Git over HTTP
send-pack Push objects over Git protocol to another repository
update-server-info Update auxiliary info file to help dumb servers
Low-level Commands / Internal Helpers
check-attr Display gitattributes information
check-ignore Debug gitignore / exclude files
check-mailmap Show canonical names and email addresses of contacts
check-ref-format Ensures that a reference name is well formed
column Display data in columns
credential Retrieve and store user credentials
credential-cache Helper to temporarily store passwords in memory
credential-store Helper to store credentials on disk
fmt-merge-msg Produce a merge commit message
interpret-trailers Add or parse structured information in commit messages
mailinfo Extracts patch and authorship from a single e-mail message
mailsplit Simple UNIX mbox splitter program
merge-one-file The standard helper program to use with git-merge-index
patch-id Compute unique ID for a patch
sh-i18n Git's i18n setup code for shell scripts
sh-setup Common Git shell script setup code
stripspace Remove unnecessary whitespace
[root@openvpn .git]#
[root@openvpn DevNet]# git rm -h
usage: git rm [<options>] [--] <file>...
-n, --dry-run dry run
-q, --quiet do not list removed files
--cached only remove from the index
-f, --force override the up-to-date check
-r allow recursive removal
--ignore-unmatch exit with a zero status even if nothing matched
--pathspec-from-file <file>
read pathspec from file
--pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character
[root@openvpn DevNet]# git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
[root@openvpn DevNet]#
ross@WIN7 MINGW64 ~ (master)
$ git --version
git version 2.18.0.windows.1
ross@WIN7 MINGW64 ~ (master)
$ git config --list
core.symlinks=true
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
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
credential.helper=manager
user.name=Ross
user.email=********@********.********
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
gui.wmstate=normal
gui.geometry=841x483+100+100 189 218
ross@WIN7 MINGW64 ~ (master)
$ vim .git/config
git config color.ui true
git config format.pretty oneline
[root@openvpn DevNet]# git --version
git version 2.29.2
[root@openvpn DevNet]#
[root@openvpn DevNet]# git config --list
user.name=rossnrachel
user.email=417588889@qq.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:rossnrachel/DevNet.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
color.ui=true
[root@openvpn DevNet]#
[root@openvpn DevNet]# git checkout -- README.md
/*
usage: git checkout [<options>] <branch>
or: git checkout [<options>] [<branch>] -- <file>...
-b <branch> create and checkout a new branch
-B <branch> create/reset and checkout a branch
-l create reflog for new branch
--guess second guess 'git checkout <no-such-branch>' (default)
--overlay use overlay mode (default)
-q, --quiet suppress progress reporting
--recurse-submodules[=<checkout>]
control recursive updating of submodules
--progress force progress reporting
-m, --merge perform a 3-way merge with the new branch
--conflict <style> conflict style (merge or diff3)
-d, --detach detach HEAD at named commit
-t, --track set upstream info for new branch
-f, --force force checkout (throw away local modifications)
--orphan <new-branch>
new unparented branch
--overwrite-ignore update ignored files (default)
--ignore-other-worktrees
do not check if another worktree is holding the given ref
-2, --ours checkout our version for unmerged files
-3, --theirs checkout their version for unmerged files
-p, --patch select hunks interactively
--ignore-skip-worktree-bits
do not limit pathspecs to sparse entries only
--pathspec-from-file <file>
read pathspec from file
--pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character
*/
[root@openvpn DevNet]# git restore README.md
/*
usage: git restore [<options>] [--source=<branch>] <file>...
-s, --source <tree-ish>
which tree-ish to checkout from
-S, --staged restore the index
-W, --worktree restore the working tree (default)
--ignore-unmerged ignore unmerged entries
--overlay use overlay mode
-q, --quiet suppress progress reporting
--recurse-submodules[=<checkout>]
control recursive updating of submodules
--progress force progress reporting
-m, --merge perform a 3-way merge with the new branch
--conflict <style> conflict style (merge or diff3)
-2, --ours checkout our version for unmerged files
-3, --theirs checkout their version for unmerged files
-p, --patch select hunks interactively
--ignore-skip-worktree-bits
do not limit pathspecs to sparse entries only
--pathspec-from-file <file>
read pathspec from file
--pathspec-file-nul with --pathspec-from-file, pathspec elements are separated with NUL character
*/
[root@openvpn DevNet]# git stash apply --help
usage: git stash list [<options>]
or: git stash show [<options>] [<stash>]
or: git stash drop [-q|--quiet] [<stash>]
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash clear
or: git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [-m|--message <message>]
[--pathspec-from-file=<file> [--pathspec-file-nul]]
[--] [<pathspec>...]]
or: git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]
[root@openvpn DevNet]#
[root@openvpn DevNet]# git pull
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
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
You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.
Already up to date.
[root@openvpn DevNet]#
[root@openvpn ~]# git clone https://github.com/github/gitignore
Cloning into 'gitignore'...
git: 'remote-https' is not a git command. See 'git --help'.
[root@openvpn ~]#
[root@openvpn ~]# git --exec-path
/opt/git/libexec/git-core
[root@openvpn ~]# cd `git --exec-path`
[root@openvpn git-core]# pwd
/opt/git/libexec/git-core
[root@openvpn git-core]# ls -lh git-remote-http*
ls: cannot access git-remote-http*: No such file or directory
[root@openvpn git-core]# ls -lh git-remote-ht*
ls: cannot access git-remote-ht*: No such file or directory
[root@openvpn git-core]#
[root@openvpn git-core]# cd /ross/DevNet/GitHub/
[root@openvpn GitHub]# git clone git@github.com:github/gitignore.git
Cloning into 'gitignore'...
remote: Enumerating objects: 8935, done.
remote: Total 8935 (delta 0), reused 0 (delta 0), pack-reused 8935
Receiving objects: 100% (8935/8935), 2.05 MiB | 1024 bytes/s, done.
Resolving deltas: 100% (4838/4838), done.
[root@openvpn GitHub]#
On My Mac Pro:
> git --exec-path
/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core
> cd `git --exec-path`
> ls -lh git-remote-http*
-rwxr-xr-x 1 root wheel 3.2M Sep 19 10:02 git-remote-http
lrwxr-xr-x 1 root wheel 15B Aug 22 22:32 git-remote-https -> git-remote-http
>
[root@openvpn tmp]# cd git/
[root@openvpn git]# git mergetool
This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more details.
'git mergetool' will now attempt to use one of the following tools:
tortoisemerge emerge vimdiff
No files need merging
[root@openvpn git]# git mergetool --tool-help
'git mergetool --tool-<tool>' may be set to one of the following:
vimdiff
vimdiff2
The following tools are valid, but not currently available:
araxis
bc3
codecompare
deltawalker
diffuse
ecmerge
emerge
gvimdiff
gvimdiff2
kdiff3
meld
opendiff
tkdiff
tortoisemerge
xxdiff
Some of the tools listed above only work in a windowed
environment. If run in a terminal-only session, they will fail.
[root@openvpn git]#