问题解决:Git Push远程已经有人提前更改过你push的分之

  1. 问题描述:对本地代码修改后,已经完成git addgit commit后,使用git push提示远程已被修改,需要pull下来。
  2. 解决问题:需要先git pull,获取到绑定的远程分支的最新commit,git pull会自动merge远程分支到本地当前分支,如果出现冲突,会提示fix conflict的地方,修改后,重新git add,git commit,git push。这样就解决了。
  3. Git fetch和git pull的区别在于:
    git fetch拉去远程分支的数据到本地仓库,并不会自动合并本地分支的commit和远程分支,我们需要自己手动合并。
    git pull,自动获取远程分支的最新commit并且合并到本地仓库。要注意获取的远程分支是当前本地分支追踪的远程分支,如果是使用git clone创建的仓库默认是远程master分支。当然我们在创建branch后通过git branch --set-upstream-to=origin/remote_branch your_branch,这样做法可以避免每次在git push时候指定远程关联的分支。

来自Git Pro:

关于git fetch
git fetch command pulls the data to your local repository—it doesn’t automatically merge it with any of your work or modify what you’re currently working on. You have to merge it manually into your work when you’re ready.
关于git pull
If you have a branch set up to track a remote branch (see the next section and Chapter 3 for more information), you can use the git pull command to automatically fetch and then merge a remote branch into your current branch.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值