【问题标题】:How to edit and push the change in initial (root) commit?如何在初始(根)提交中编辑和推送更改?
【发布时间】:2020-01-04 14:05:35
【问题描述】:

所以,简单解释一下我现在的情况:

  • 我不断将更改推送到 origin master(尚未创建分支)
  • 我决定更改 Github Repository 初始提交的提交消息
  • 我做了$ git rebase -i --root 并成功更改了提交消息
  • 我尝试通过 $ git push --force 强制推送,但得到以下错误:

    fatal: The current branch master has no upstream branch.  
    To push the current branch and set the remote as upstream, use 
    
    git push --set-upstream origin master.
    
  • 我尝试按照说明进行操作,但得到:

! [rejected]        master -> master (non-fast-forward) error: failed
to push some refs to 'git@github.com:BLAHBLAH.git' hint: Updates were
rejected because the tip of your current branch is behind hint: its
remote counterpart. Integrate the remote changes (e.g. hint: 'git pull
...') before pushing again. hint: See the 'Note about fast-forwards'
in 'git push --help' for details.

我做错了什么?

【问题讨论】:

    标签: git github rebase


    【解决方案1】:

    如果你只是想修改最后一次提交 - 使用 ammend

    # Change the latest commit message
    git commit --amend --no-edit -m"<new message>
    

    推送您的更改:

    使用这个命令:

    # It will set up the "track" and will force the push
    git push --set-upstream origin master -f
    

    【讨论】:

    • 成功了,谢谢!那 -f 到底有什么变化?
    • -f = 强制推送并覆盖现有内容
    猜你喜欢
    • 2011-01-05
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 2015-07-04
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多