search

Home  >  Q&A  >  body text

The code on Github and the local code are out of sync, how to solve it?

Because sometimes there is no Internet connection locally, and then after accidentally submitting the new file code to github, the files seem to be marked as submitted the next time they are submitted (actually they are not submitted), and then the github and local codes are not Sync

高洛峰高洛峰2806 days ago737

reply all(9)I'll reply

  • 迷茫

    迷茫2017-05-02 09:35:16

    No way.

    My steps are usually like this
    git pushgit push
    如果失败的话,说明网络上的版本已经更改过了,那就
    git pull
    如果失败的话,说明网络的版本和本地的版本在合并时可能产生冲突,那就
    git stash(把本地的修改全部缓存起来)
    然后再
    git pull
    然后再
    git stash pop(把缓存起来的修改恢复)
    然后如果有冲突解决冲突,没有就
    git pushIf it fails, it means that the version on the network has been changed, then

    git pull

    If it fails, it means The network version and the local version may conflict when merging, then

    git stash (cache all local changes)🎜and then 🎜git pull🎜then Then 🎜git stash pop(restore the cached changes)🎜Then if there is a conflict, resolve the conflict, if not, just 🎜git push🎜 🎜Use Turtle’s Git tool under Windows. 🎜

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-02 09:35:16

    Execute as needed

    git pull 
    git push origin master

    reply
    0
  • 阿神

    阿神2017-05-02 09:35:16

    How can I submit it to github without local network?

    reply
    0
  • PHP中文网

    PHP中文网2017-05-02 09:35:16

    = = Is the submission you are talking about a commit?

    If it is a commit, there is no problem, because the commit is to submit the code to the local warehouse

    For example, when you don’t have internet

    //改了一些文件
    git commit -am 'fix a bug'
    
    //又改了一些文件
    git commit -am 'add new func'

    These changes are all submitted to the local repository, but the remote repository remains unchanged
    wait until you have internet access

    git push

    At this time, the remote warehouse will be compared with your local warehouse, and then the changes will be pushed to the remote warehouse.
    The remote warehouse will also have these two commit records at this time.
    'fix a bug'
    'add new func'

    Recommend you to read git tutorial

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:35:16

    When there is no network, it is submitted to its own local library. If you submit to the remote library, you need to git push

    reply
    0
  • 高洛峰

    高洛峰2017-05-02 09:35:16

    If you are very sure that it is not because someone else updated that your request cannot be completed, but because the last submission caused a problem with the remote version library due to network reasons (unlikely), and you are very sure that the local library is No problem, you can:

    git push origin master:master --force

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:35:16

    commit is in the local warehouse and needs to be pulled up

    reply
    0
  • PHPz

    PHPz2017-05-02 09:35:16

    I think so, git and github are two different concepts. I understand that you submitted it to the local version control management without an Internet connection, but did not push to the version control of the remote server. Git is distributed version control, that is, a complete version library is maintained remotely and locally. If you connect to the Internet to pull the code, you will pull the code from the server and merge it into the local branch. If you use fetch, you need to check whether you have merge remote branches.

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-02 09:35:16

    First of all, let’s distinguish what is Git and what is Github.

    Then, the Git commit will not be pushed to the remote library. Could it be that you used SVN before?

    reply
    0
  • Cancelreply