gpt4 book ai didi

Git:推送被拒绝

转载 作者:太空狗 更新时间:2023-10-29 14:43:48 30 4
gpt4 key购买 nike

我有一个团队,我们正在开展一个项目。我们的一名团队成员在 GitHub 上创建了一个存储库,并将其他人添加为协作者。我的团队成员将我们的代码提交到这个存储库。我对自己的部分进行了更改,当我尝试提交时,我遇到了错误。如何将更改提交到我作为协作者的存储库?

这就是我所做的:

git remote add origin https://github.com/xxx/xxx.git (added a repository where I'm a collaborator)

`git push origin master
To https://github.com/xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxx/xxx.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.

git pull origin master
warning: no common commits
remote: Counting objects: 145, done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 145 (delta 67), reused 145 (delta 67), pack-reused 0
Receiving objects: 100% (145/145), 55.90 KiB | 0 bytes/s, done.
Resolving deltas: 100% (67/67), done.
From https://github.com/xxx/xxx
* branch master -> FETCH_HEAD
* [new branch] master -> or/master
fatal: refusing to merge unrelated histories

我只想更新我的部分并将其提交到存储库。我没有自己的存储库。

谢谢

最佳答案

看起来您的两个 master 分支出现了分歧。

# HEAD at your master
$ git checkout master

# your master on a new branch
$ git checkout -b diverged.master

# get origin's master
$ git checkout master
$ git fetch origin master
$ git reset --hard origin/master

# Create a new branch for the diverged feature
$ git checkout -b feature.branch

# Merge your diverged changes into the new feature branch
$ git merge diverged.master

# Do any conflict resolutions

# Merge feature branch to master
$ git checkout master
$ git merge feature.branch

# Push to remote
$ git push origin master

编辑

我错过了关于这是一个全新的 repo 的部分.. 让这更容易一些

# HEAD at your master
$ git checkout master

# your master on a new branch
$ git checkout -b diverged.master

# delete master branch
# git branch -D master

# pull master from origin
$ git pull origin master

# HEAD at origin's master
$ git checkout origin master
$ git pull # for good measure

# merge your changes
$ git merge diverged.master

# push your changes
$ git push origin master

关于Git:推送被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40697415/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com