提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
Git
版本管理
软件安装
https://gitforwindows.org/
#安装后通过以下命令查看
git --version
git设置邮箱 姓名
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
常用命令
命令 | 说明 |
---|---|
git clone [仓库地址warehouse address] | 拉取git仓库代码 |
git log --oneline | 查看log日志以及 |
git clone -b dev [仓库地址warehouse address] | 克隆指定分支(dev) |
git branch [branchname] | 新建分支 |
git branch -a | 查看当前所有分支 |
git branch -m [branchname] | 重命名当前分支 |
git pull origin [branchname] | 将远程分支拉取到本地 |
git fetch --all | 拉取所有分支远程代码 |
git checkout [branchname] | 切换到该分支 |
git checkout -b [branchname] [origin/branchname] | 新建本地分支拉取指定的远程分支 |
git checkout -b [new branchname] | 以历史版本 commit-id 创建新分支 |
git commit --amend | 进入vim编辑模式 修改commit提示语 |
git reset --hard | 恢复到指定提交版本 |
git reset --soft HEAD | 保留工作区的内容,只回退commit的动作 |
git revert | 撤销某一次的提交 |
git cherry-pick | 将指定commit合并至当前分支 |
git merge [branchname] | 合并分支 |
git push --set-upstream origin [branchname] | 将本地分支提交到远程 |
git branch -D [branchname] | 删除本地分支 |
git push origin --delete [branchname] | 删除远端分支 |
.gitignore
.gitignore用于定义忽略提交的文件
- 所有空行或者以注释符号
#
开头的行都会被 Git 忽略。 - 匹配模式最后跟反斜杠(
/
)说明要忽略的是目录。 - 可以使用标准的 glob 模式匹配。
.idea
/vendor
.env
/node_modules
/public/storage
*.txt
Tag
Git 也可以对某一时间点上的版本打上标签 ,用于发布软件版本如 v1.0
- 添加标签
git tag v1.0
- 列出标签
git tag
- 推送标签
git push --tags
- 删除标签
git tag -d v1.0.1
- 删除远程标签
git push origin :v1.0.1
使用场景
场景一:创建仓库
mkdir creat-git
cd creat-git
git init
touch README.md
git add README.md
git commit -m "first commit"
#添加远程仓库
git remote add origin https://gitee.com/wangsitong920805/creat-git.git
#推送数据到远程仓库
git push -u origin "master"
#删除远程仓库关联
git remote rm origin
#查看远程库
git remote -v
通过 clone 克隆的仓库,本地与远程已经自动关联,上面几步都可以省略。
场景二:回滚到指定commit
#拷贝版本号
git log
git reset --hard 目标版本号
#强制提交
git push -f
场景三: 合并多次commit
git log --oneline<br/>
git rebase -i [logNumberdd]<br/>
弹出编辑器 在vi编辑中保留第一个pick剩下的改成s ,退出<br/>
弹出编辑器 之后将多次提交的message删除,修改最终的message,退出<br/>
git push