git 常用命令 和常见问题

git init 初始化

git clone http://...  克隆项目

git add 文件名   添加文件

git status   查看状态

git commit -m '备注'  添加备注

 

git push origin master   推送到云端

//git pull <远程主机名> <远程分支名>:<本地分支名>

 

*git push -f  强推(有时候出现冲突推送不上去时候使用)

 

git checkout -b dev  创建分支

    --- Switched to a new branch 'dev'

git add

git status

git commit -m ""

git checkout master

    --- Switched to a branch 'master'

git merge dev

git push origin master

 

 

 

//当出现这种错误时,表名readme文件没有更新

! [rejected]          dev -> dev (non-fast-forward)

error: failed to push some refs to 'http://code.fieldschina.com/web/oa.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

//此时需要

git pull --rebase origin dev

 

如果继续提交,git status 出现rebase in progress; onto ed15f09a  //之前或者刚刚用过 git rebase,但上一次的进程还没有完成。

 

则需 git rebase --continu

 

git push origin 远程分支:本地分支

 

 

 

 

 

推送本地分支local_branch到远程分支 remote_branch并建立关联关系

 

    a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch

      git push

    b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch

     git push -u origin/remote_branch

    c.远程没有有remote_branch分支并,本地已经切换到local_branch

    git push origin local_branch:remote_branch

 

    

   

error: Pulling is not possible because you have unmerged files.

使用 git reset --hard FETCH_HEAD解决冲突

 

git MERGING状态

使用 git reset --hard head解决

 

 

git pull冲突 error: Your local changes to the following files would be overwritten by merge

如果希望用代码库中的文件完全覆盖本地工作版本

git reset --hard

git pull

 

 

Git取消add状态

git reset <HEAD>

    

    

查看本地对应的远程分支  git branch -vv

 

git stash save 'messag' 将修改的文件存入暂存区 不会提交

 

git stash pop 释放暂存区文件

 

git stash list 查看现有stash 

 

 

撤销commit操作并返回到未commit状态

git log

 

git reset --hard commit_B_hash

 

git reset commit_A_hash

 

 

 

主分支对应的本地分支,切换到测试分支本地分支   git checkout -b locdev origin/develop

   

    

Git reset --hard commit_id(可用 git log –oneline 查看)

git push origin HEAD --force #远程提交回退

 

 

    

    

    

    

    

    

    

    

    

    

    

    

    

    

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值