git常用命令和使用步骤

建立本地仓库
git init

查看用户名和邮箱地址:
git config user.name
git config user.email

修改用户名和地址
git config --global user.name "your name"
git config --global user.email "your email"

git branch 查看当前分支
git branch -a查看远程分支
git branch -d  dev 删除本地dev分支
git checkout -b 新分支名 (创建并切换到分支下)
例如:git checkout -b dev
git cheackout -b dev origin/dev 创建本地分支dev并切换到远程dev分支


删除当前git版本库信息(一般不建议删除,除非提交新的地址和项目) 
git remote remove origin

查看当前提交地址 
git remote -v 


git commit告诉Git,把文件提交到仓库
git status来查看是否还有文件未提交


第一步:是使用 git add 把文件添加进去,实际上就是把文件添加到暂存区。git add readme.txt(文件名) git add .添加所有文件

第二步:使用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支上。
git commit -m '这里写上注释'

git remote add origin https://github.com/testgit.git 添加到新的仓库上面

已有git地址情况下,修改新的git地址:
git remote set-url origin https://github.com/test.git
克隆代码:git clone 项目地址


git pull把远程最新资源拉到本地库进行合并,如果有冲突的话得手动解决
git pull origin dev(master 主分支) 合并分支
 
git push -u origin master 把本地库的内容推送到远程主分支
git push -u origin dev   把本地库的内容推送到远程dev分支

从现在起,只要本地作了提交,就可以通过如下命令:

git push origin master


git reflog 查看提交版本


回退版本号
git reset --hard d597768 需要回退的版本号:d597768

git clean -f .git/index.lock 当前提交发生异常的时候执行

Please enter a commit message to explain why this merge is necessary.解决方法
1.按键盘字母 i 进入insert模式

2.修改最上面那行黄色合并信息

第二:

1.按键盘左上角"Esc"

2.输入冒号加wq   ":wq",  按回车键,意思就是就是忽略这个提示

用于第一次提交合并之前的历史
git pull origin master --allow-unrelated-histories


第一次提交发现问题
Updates were rejected because the tip of your current branch is behind hint:
先pull远程仓库,再push即可
git pull origin master --allow-unrelated-histories (该选项可以合并两个独立启动仓库的历史)
git push -u origin master


跟远程库关联
git branch --set-upstream-to=origin/develop远程分支名 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值