Git学习(01)_基本命令
常用基本命令
1. 初始化当前目录
#初始化当前目录
git init
2. 常用
# clone develop分支
git clone -b develop git@git.test.com
# 查看远程所有分支
git branch -r
# 查看远程 已经合并的分支
git branch -r --merged
# 查看远程服务器状态
git remote
git remote -v #查看详细信息, 显示拉取和推送的地址
# 拉取 pull, 使用rebase 直接合并代码, 不会merge, 不会产生节点
git pull --rebase
#文件加入到暂存区, 文件与文件之间 空格分隔; 也可以使用通配符;
git add readme.md ant.txt
git add *.txt
#提交分支
git commit -m "注释说明"
#推送远程分支
git push
# 本地关联远程
git remote add origin git@xxx.github.com
#查看状态
git status
#查看提交信息
git log
git log --graph #图标
git log --oneline
#对比
git diff
#撤销
git checkout ./文件名称
# 检查该文件是否 有忽略
git check-ignore -v name.file
# 查看标签
git tag
git tag tagName # 新建标签, 给当前打标签
git log --oneline; git tag tagName 611b0ef # 为指定提交 添加标签
git show tagName #显示该标签名下的信息, 不是时间排序, 按照名称排序
git tag -d tagName #删除标签, 本地
git push orgin tagName #提交标签到远程服务器, 如果删除了本地的, 也会删除远程
git push orgin --tag #提交所有标签到远程, 如果删除了本地的, 也会删除远程
#回退版本, 强制回退, 丢弃本地的修改
git reset --hard 1094a
# 撤销提交
git revert 452ab33
#回退文件
git checkout fileName
- 查看某个文件的提交历史
git log --pretty=online filePath
- 修改提交的中文显示问题
- 修改commit注释
# 提交到最近一次commit
git commit --amend
- stash 隐藏工作修改的缓存, 通常修改紧急bug使用
#隐藏工作分区, 修复紧急bug时使用
git stash
git stash save "注释"
git stash list
# 显示修改的文件列表
git stash@{$num} show
# 显示修改的文件内容
git stash show -p
# 恢复并删除
git stash pop
# 只恢复不删除
git stash apply
# 删除
git stash drop
3.更新 gitignore 生效
git rm -r --cached .
git add .
git commit -m "update .gitignore"
git push