https://git-scm.com/book/zh/v2 <=> https://github.com/progit/progit2-zh
Git 官方下载
Windows XP 可以用 v2.10.0
https://github.com/git-for-windows/git/releases/tag/v2.10.0.windows.1
CentOS 安装
yum install git
git --config user.email ""
git --config user.name ""
不生效解决方法 先 Unstage From Commit
git rm -r --cached .
git add .
git commit -m "update .gitignore"
查看分支
git branch [-r|-a]
-
-r 远程
-
-a 所有
创建分支
git branch <branch_name> [commit_id]
切换分支
git checkout [-b] <branch_name>
git checkout <commit_id> -b <branch_name>
- -b 创建+切换
参考:
推送分支
git push origin <branch_name>
# 重命名远程分支
git push origin [-u] <newname>
删除本地分支
git branch -d <branch_name>
删除远程分支
git push origin :<branch_name>
重命名分支
git branch -m [<oldname>] <newname>
# 删除远程分支
git push origin :<oldname>
# 推送新分支
git push origin <newname|HEAD>:refs/heads/<newname>
参考:
- https://stackoverflow.com/questions/6591213/how-do-i-rename-a-local-git-branch
- https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/
远程仓库的重命名
git remote rename old-origin new-origin
远程仓库的删除
git remote rm old-origin
%ProgramFiles%/Git/mingw64/share/doc/git-doc/git-remote.html
列出标签
git tag
git tag -l "v1.8.5*"
# 远程
git ls-remote --tag[s]
查看标签详情
git show <tagname>
创建标签
git tag <name> [commit_id]
git tag -a <name> -m "<message>" [commit_id]
检出标签
git checkout <tagname>
删除标签
git tag -d <tagname>
# 远程
git push origin -d <tagname>
git push origin :<tagname>
git push origin :refs/tags/<tagname>
推送标签
git push orgin <tagname>
# 所有标签
git push [orgin] --tags
命令行创建新仓库
echo "# mysql-tutorial" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/wuding/mysql-tutorial.git
git push -u origin master
推送到已有的仓库
git remote add origin https://github.com/wuding/mysql-tutorial.git
git push -u origin master
2 种方法,可以同时推送,但要单独拉取
.get/config
[remote "origin"]
url = https://gitee.com/excai/note.git
url = https://github.com/wuding/note.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "github"]
url = https://github.com/wuding/note.git
fetch = +refs/heads/*:refs/remotes/github/*
- remote 添加 url
git remote set-url --add origin https://github.com/wuding/note.git
- 添加 remote
git remote add github https://github.com/wuding/note.git
git config alias.pushall "!git push origin && git push github"
另外还有一种方法用 Webhooks 实现双向同步
Git学习总结(16)——开源世界GitHub和开源中国GitOSChina同步提交
绑定仓库:
设置 -> 集成 -> GitHub
安装
npm install -g gitbook-cli
gitbook -V
初始化文件目录
gitbook init
# 编辑 SUMMARY.md 再次执行
目录 SUMMARY.md
* [Chapter1](chapter1/README.md)
* [Section1.1](chapter1/section1.1.md)
* [Section1.2](chapter1/section1.2.md)
* [Chapter2](chapter2/README.md)
gitbook serve
构建静态页 _book
gitbook build
导出 PDF
需要安装 Calibre
gitbook pdf ./ ./mybook.pdf
参考:
命令
gitbook init //初始化目录文件
gitbook help //列出gitbook所有的命令
gitbook --help //输出gitbook-cli的帮助信息
gitbook build //生成静态网页
gitbook serve //生成静态网页并运行服务器
gitbook build --gitbook=2.0.1 //生成时指定gitbook的版本, 本地没有会先下载
gitbook ls //列出本地所有的gitbook版本
gitbook ls-remote //列出远程可用的gitbook版本
gitbook fetch 标签/版本号 //安装对应的gitbook版本
gitbook update //更新到gitbook的最新版本
gitbook uninstall 2.0.1 //卸载对应的gitbook版本
gitbook build --log=debug //指定log的级别
gitbook build --debug //输出错误信息
多语言 LANGS.md
* [English](en/)
* [French](fr/)
* [Español](es/)
配置 book.json
{
//样式风格配置格式
"styles": {
"website": "styles/website.css",
"ebook": "styles/ebook.css",
"pdf": "styles/pdf.css",
"mobi": "styles/mobi.css",
"epub": "styles/epub.css"
},
//插件安装配置格式
"plugins": ["myplugin"],
"pluginsConfig": {
"myPlugin": {
"message": "Hello World"
}
}
}
C:\Users\Administrator\GitBook\Library\Import\testbook
https://github.com/GitbookIO/plugin-hints
https://github.com/nvie/gitflow
用户文件夹 %USERPROFILE% 新建文件 .git-credentials
https://{username}:{password}@github.com
Bash 命令
git config --global credential.helper store
会在 .gitconfig 添加
[credential]
helper = store
生成 key
ssh-keygen -t rsa -C [email protected]
# 用户文件夹 .ssh 目录下会生成 id_rsa.pub
Git GUI 菜单 help > Show SSH Key
使用git提交到github,每次都要输入用户名和密码的解决方法
https://github.com/fork-copy/Notes/blob/master/Tools/Git/Git_push_password_less.md
The remote end hung up unexpectedly
行尾结束符 Windows 回车换行,Linux Mac 换行
提交时 CRLF 转 LF 签出时 LF 转 CRLF
git config --get core.autocrlf
git config --global core.autocrlf true
# true 自动转换 input 提交时转换 false 不转换
https://git-scm.com/book/zh/v1/自定义-Git-配置-Git#格式化与空白
git config --global core.autocrlf false
git config --global user.name "yourname"
git config --global user.email "youremail"
ssh-keygen -t rsa -C "youremail"
删除用户目录里的 .ssh 文件夹中的文件 known_hosts,执行上一条问题解决 SSH key 命令,添加 SSH key 到 GitHub
ssh -T [email protected]
HTTPS 方式提示验证错误,可以如下解决:
git config --system --unset credential.helper
重新打开 Git GUI 就会再次提示输入用户名和密码
控制面板\所有控制面板项\凭据管理器
Windows 凭据\普通凭据
删除 git:https://github.com
git pull origin master --allow-unrelated-histories
编辑以下文件和内容:
%USERPROFILE%/.ssh/config
Host *
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
$ git --help
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --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
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
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
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
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.
# 删除提交
git reset --hard <commit_id>
# 创建新的提交
git revert