Git常用命令
Git 常用命令
查看分支
查看本地分支
git branch
查看远程分支
git branch -r
查看所有分支[本地+远程]
git branch -a
新建分支
新建本地分支
git checkout -b branchName
新建远程分支
在本地分支的基础上,直接将新建的本地分支,push 到远程即可,命令如下
git push origin localBranchName:remoteBranchName--一般这里远程分支和本地分支取一样的名字
例如:
git push origin 20200717_test:20200717_test
删除分支
删除本地分支:
git branch -d branchName
删除远程分支:
git push origin --delete branchName
同步远程数据到本地:
git fetch origin // 默认是指定的是master 分支, 所以 等价于 git fetch origin master
合并分支【这里合并远程master分支】
git merge origin/master 【我使用命令时存在冲突,使用的IDEA解决了冲突再进行合并的】
推送到远程
git push 【这也是用IDEA推送的】,使用命令会提示:git push --set-upstream origin release/2020_12_11_cvalue
我这里使用IDEA直接推送
切换分支
git checkout hotfix/2021_01_07_continue_rate
回退到指定版本
查看提交记录
git log
git revert <commitId> //commitId 为 git log 中显示的id
打tag
以测试完成的test分支为例,打pre的tag
git checkout test
git pull
git checkout -b pre
git push --set-upstream origin pre
git tag -a "glyh-application-v1.0.0-pre" -m "预发布/试运行打包"
git push origin "glyh-application-v1.0.0-pre"
为每个项目配置独立账号和邮箱
git config user.name "your_name"
git config user.email "your_email"
临时保存 Git stash
暂存工作空间
git stash -m "自定义暂存记录消息,如果没定义,系统会使用默认自定义"
提取暂存空间
git stash pop 【这样会将保存的stash给删除】
git stash apply 【不会删除保存的stash--推荐使用】

浙公网安备 33010602011771号