AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1715499
Accepted
Second Person Shooter
Second Person Shooter
Asked: 2022-04-10 22:25:52 +0800 CST2022-04-10 22:25:52 +0800 CST 2022-04-10 22:25:52 +0800 CST

在没有变基的情况下,如何将本地存储库推送到使用许可文件初始化的新远程 github 存储库?

  • 772

我有一个带有一些提交的本地仓库。由于我想将其公开给其他人,我需要将其推送到 Github 上新创建的远程仓库。新创建的远程仓库使用许可文件初始化(因为本地仓库没有许可文件)。

由于在远程仓库中添加了文件,因此推送git push -u origin main(我的本地分支也使用main而不是master作为主分支)会产生错误。license

C:\test>git push -u origin main
To https://github.com/pstricks-fans/test.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/pstricks-fans/test.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. 

我按照以下提示进行拉动。

C:\test>git pull origin main
From https://github.com/pstricks-fans/test
 * branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

合并是不可能的。

有人告诉我,我必须使用以下内容重新设置基础。

C:\test>git pull origin main --rebase
From https://github.com/pstricks-fans/test
 * branch            main       -> FETCH_HEAD
Successfully rebased and updated refs/heads/main.

问题

有没有其他没有变基的解决方案(出于学习目的)?不建议对公共 repo 进行变基(如 git 文档所述)。

git github
  • 2 2 个回答
  • 335 Views

2 个回答

  • Voted
  1. Best Answer
    Neil
    2022-04-11T16:13:50+08:002022-04-11T16:13:50+08:00

    您的最终历史记录有三个选项。

    1. 您的本地提交保持不变,而且您还有一个包含许可证文件的本地提交。一种方法是使用git cherry-pick origin/master将公共提交变基到本地分支,然后git push --force-with-lease用您的分支覆盖公共分支。虽然覆盖公共分支通常是不可取的,但如果没有其他人实际克隆它,这不是问题。

    2. 如您所知,您可以重新定位本地提交,因此它们的历史现在遵循许可证文件提交的历史。

    3. 您合并了本地和远程分支,但由于它们没有共同的祖先,Git 担心您可能会犯错误,因此您需要使用 来确认它,正如Stack Overflow 问题git pull origin main --allow-unrelated-histories中所讨论的那样。

    • 3
  2. user1686
    2022-04-10T22:46:37+08:002022-04-10T22:46:37+08:00

    如果您想让许可证文件显示在所有现有提交中,那么变基(或其他形式的历史重写)是唯一的选择。如果不更改提交 ID,则无法将文件添加到现有提交中。

    (合并本地和 GitHub 初始化的历史,虽然完全有可能,但实际上并不能实现这一点 - GitHub 提供的文件只会出现在“合并”提交中及以后,但合并不会更改存储库过去的内容。 )

    如果您只希望许可证文件显示在新提交上(这可能很好),那么通常只需将其添加+提交到您的本地存储库,然后git push --force到 GitHub,丢弃它初始化的任何内容。

    GitHub 的“Initialize with...”功能仅适用于全新的存储库——在发布现有存储库时它是无用的。

    • 2

相关问题

  • 更改 git init 默认分支名称

  • 混帐添加。命令不工作

  • 提交后从git恢复已删除的文件

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve