config
git config 进行配置
1 | git config --global user.name <name> |
.gitconfig 配置文件
/etc/gitconfig系统中对所有用户git config --system读写这个文件~/.gitconfig适用于当前用户git config --global读写这个文件${dir}/.git/config针对当前项目有效git config --local读写这个文件
每一个级别的配置都会覆盖上层的相同配置
init
git init在现有目录中初始化仓库git init dir创建dir目录并初始化成git项目
clone
git clone 克隆现有的仓库
1 | git clone [<options>] [--] <repo> [<dir>] |
status
git status 检查当前文件状态
1 | git status |
- ?? 标记:新添加的未跟踪文件
- A 标记:新添加到暂存区中的文件
- M 标记:修改过的文件
出现在右边的 M 表示该文件被修改了但是还没放入暂存区,出现在靠左边的 M 表示该文件被修改了并放入了暂存区
add
git add 跟踪新文件、暂存已修改文件
1 | git add <files> |
diff
git diff 比较差异
1 | --name-only |
commit
git commit 提交更新
1 | git commit -m "first commit" |
rm, mv
git rm 移除文件
从暂存区域移除,并连带从工作目录中删除指定的文件
如果删除之前修改过并且已经放到暂存区域的话,则必须要用强制删除选项 -f
把文件从 Git 仓库中删除(亦即从暂存区域移除),但仍然希望保留在当前工作目录中 –cached
git mv 移动文件
这条命令等价于
1 | mv file1 file2 |
log
git log 查看提交历史
1 | git log |
remote
git remote 远程仓库
1 | git remote |
fetch
git fetch 从远程仓库中获得数据
push
git push 推送到远程仓库
tag
git tag 标签
1 | git tag # 列出标签 |
branch
git branch git分支
1 | git branch # 显示当前所有分支, -v 还会显示各分支最后一次提交, --merged 与 --no-merged显示已合并与未合并的分支 |
merge
git merge 分支合并
rebase
git rebase 变基
https://stackoverflow.com/questions/22992543/how-do-i-git-rebase-the-first-commitgit rebase -i --root
reset
git reset 回退
1 | git reset --hard [commit_id] |
gitignore
.gitignore 忽略文件
文件 .gitignore 的格式规范如下:
- 所有空行或者以 # 开头的行都会被 Git 忽略。
- 可以使用标准的 glob 模式匹配。
- 匹配模式可以以(/)开头防止递归。
- 匹配模式可以以(/)结尾指定目录。
- 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反。
所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。
ssh密钥复制
1 | chmod 600 ~/.ssh/id_rsa |
bisect
https://www.ruanyifeng.com/blog/2018/12/git-bisect.html
sshkey error
- https://stackoverflow.com/questions/69875520/git-error-no-matching-host-key-type-found-their-offer-ssh-rsa
- https://help.gitee.com/enterprise/code-manage/%E6%9D%83%E9%99%90%E4%B8%8E%E8%AE%BE%E7%BD%AE/%E9%83%A8%E7%BD%B2%E5%85%AC%E9%92%A5%E7%AE%A1%E7%90%86/SSH%20Key%20%E7%AA%81%E7%84%B6%E5%A4%B1%E6%95%88%E9%97%AE%E9%A2%98%E8%A7%A3%E7%AD%94%E5%8F%8A%E5%A4%84%E7%90%86%E5%8A%9E%E6%B3%95