代码之家  ›  专栏  ›  技术社区  ›  shin

添加Git支持后拒绝Git推送

git
  •  0
  • shin  · 技术社区  · 4 年前

    在添加Git支持后,我无法推进回购。 我按错误提示拉了车,但也没用。

    我该如何解决这个问题?

    svelte-flow on  main [⇡] is 📦 v0.2.4 via  v16.13.0 
    ❯ ggp                     
    To github.com:shinokada/svelte-flow.git
     ! [rejected]        main -> main (fetch first)
    error: failed to push some refs to 'github.com:shinokada/svelte-flow.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    svelte-flow on  main [⇡] is 📦 v0.2.4 via  v16.13.0 took 2s 
    ❯ gst
    On branch main
    Your branch is ahead of 'origin/main' by 2 commits.
      (use "git push" to publish your local commits)
    
    nothing to commit, working tree clean
    
    svelte-flow on  main [⇡] is 📦 v0.2.4 via  v16.13.0 
    ❯ ggp
    To github.com:shinokada/svelte-flow.git
     ! [rejected]        main -> main (fetch first)
    error: failed to push some refs to 'github.com:shinokada/svelte-flow.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    svelte-flow on  main [⇡] is 📦 v0.2.4 via  v16.13.0 
    ❯ git pull                         
    remote: Enumerating objects: 5, done.
    remote: Counting objects: 100% (5/5), done.
    remote: Compressing objects: 100% (3/3), done.
    Unpacking objects: 100% (4/4), 1.01 KiB | 172.00 KiB/s, done.
    remote: Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
    From github.com:shinokada/svelte-flow
       df125f9..381c351  main       -> origin/main
    hint: You have divergent branches and need to specify how to reconcile them.
    hint: You can do so by running one of the following commands sometime before
    hint: your next pull:
    hint: 
    hint:   git config pull.rebase false  # merge
    hint:   git config pull.rebase true   # rebase
    hint:   git config pull.ff only       # fast-forward only
    hint: 
    hint: You can replace "git config" with "git config --global" to set a default
    hint: preference for all repositories. You can also pass --rebase, --no-rebase,
    hint: or --ff-only on the command line to override the configured default per
    hint: invocation.
    fatal: Need to specify how to reconcile divergent branches.
    
    svelte-flow on  main [⇕] is 📦 v0.2.4 via  v16.13.0 took 2s 
    ❯ git pull origin main
    From github.com:shinokada/svelte-flow
     * branch            main       -> FETCH_HEAD
    hint: You have divergent branches and need to specify how to reconcile them.
    hint: You can do so by running one of the following commands sometime before
    hint: your next pull:
    hint: 
    hint:   git config pull.rebase false  # merge
    hint:   git config pull.rebase true   # rebase
    hint:   git config pull.ff only       # fast-forward only
    hint: 
    hint: You can replace "git config" with "git config --global" to set a default
    hint: preference for all repositories. You can also pass --rebase, --no-rebase,
    hint: or --ff-only on the command line to override the configured default per
    hint: invocation.
    fatal: Need to specify how to reconcile divergent branches.
    
    
    1 回复  |  直到 4 年前
        1
  •  1
  •   dan1st    4 年前

    您有远程分支没有的提交,并且远程分支包含本地分支中没有的提交。

    A-local
    \
     - remote
    

    Git保护您不使用收到的错误覆盖远程分支中的更改。

    Git允许合并这些更改,但您没有告诉它使用什么Streegy。拉动时,它建议您使用以下选项:

    合并

    合并分支意味着您将基于两个提交(本地和远程提交)创建一个提交。这是标准行为。

    A - local   - merge commit
    \          /
     - remote - 
    

    您可以使用 git config pull.rebase false .

    重基

    重定基址意味着您要将本地分支置于远程分支之上:

    A - remote - local
    

    您可以使用 git config pull.rebase true 或者通过使用 git pull --rebase .

    只允许快进

    您还可以以不允许这种情况的方式配置拉入。如果它需要合并本地分支和远程分支都有不同提交的更改,它将失败。

    可以使用 git config pull.ff only