【问题标题】:Replace all files and folders in branch with (currently) non-git folder用(当前)非git文件夹替换分支中的所有文件和文件夹
【发布时间】:2021-01-25 12:01:39
【问题描述】:

请记住,我对 Git 完全陌生,对术语了解不多

我在 GitHub 存储库上有一个分支 reference-redo 和一个不同的(非 git)文件夹,我想用它替换 reference-redo 分支的内容。

在 Git bash 中打开文件夹:

git init:添加一个.git 文件夹(说它初始化了一个空的 Git 存储库)

git add .:添加所有文件和文件夹(有关于 LF 被 CR LF 替换的警告但没有错误)

git commit -m 'Fixed usage of references for ObjectPointer type': 'create mode ...' 为 14 个文件

git remote add origin https://github.com/me/repo-name.git: 没有输出也没有错误

git checkout -b reference-redo: 切换到新分支'reference-redo'

git remote -v

git push origin reference-redo

 ! [rejected]        reference-redo -> reference-redo (fetch first)
error: failed to push some refs to 'https://github.com/me/repo-name.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 remote show origin 表明分支确实存在:

  Remote branches:
    functions      new (next fetch will store in remotes/origin)
    master         new (next fetch will store in remotes/origin)
    reference-redo new (next fetch will store in remotes/origin)
  Local refs configured for 'git push':
    master         pushes to master         (local out of date)
    reference-redo pushes to reference-redo (local out of date)

git-push

【问题讨论】:

    标签: git github version-control git-branch


    【解决方案1】:

    如果您想覆盖该分支中的整个历史记录,您可以git push --force

    否则,请通过在本地文件管理器中删除和复制文件进行定期更新,然后像任何其他时间一样提交。

    【讨论】:

    • 这和-f一样吗,有没有潜在的负面影响?
    • 是的。是的,如果其他人已经获取了那个分支,那就有问题了。
    猜你喜欢
    • 2011-08-07
    • 2017-05-10
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 2017-11-19
    • 2019-10-01
    相关资源
    最近更新 更多