linux git 操作

linux git 操作

branch 操作

新建分支new_branch同步远程分支origin/xxx

git checkout -b 新分支名 origin/远程分支名

新分支同步到远程仓库

git push origin 新分支名

查看本地分支

git branch

查看远程分支

git branch -r

查看所有分支

git branch -a

拉取远程分支(如果不是origin,则需要换成对应的名称)

git remote update origin --prune

切换分支(不需要 origin)

git checkout 分支名

拉取当前分支代码

git pull origin 分支名

删除本地分支

git branch -d 分支名

删除远程分支

git push origin --delete 分支名

提交操作

将修改文件提交到暂缓区

git add 文件名

提交修改

git commit -m “First commit”

推送到远程库

git push origin maste

查看本地修改

git status

如果在远程服务器上有代码更新,直接丢弃所有更改的命令

git checkout ./

回滚提交(将当前branch的HEAD指针指向commit hash)

git reset --hard resetVersionHash

查询git提交版本的hash

git rev-list --max-count=2 HEAD

查询当前提交版本的hash

git rev-parse HEAD

分支合并

合并 分支 到本地分支

git merge 分支名

查看合并状态 并解决冲突

git status

将冲突文件提交至 暂缓区

git add 冲突文件

提交merge 后的结果

git commit -m “merge commit”

推送合并结果到远程库

git push origin 分支名

问题解决

git 冲突解决

needs merge error: you need to resolve your current index first

解决方案:本地回退到当前版本,不影响远程库

git reset --hard

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值