在 github 上,我 fork 了另一个项目的旧版本。我做了一些更改,并试图将它们推送到我在 github 上的分支上。我在本地提交了更改,然后尝试了 git push,但这只是告诉我“一切都是最新的”。然而,当我浏览 github 上的项目时,没有任何变化:它仍然显示我的 fork 上的文件(来自最新版本),未修改。如何将更改推送到我的 github 帐户?
(我意识到这不是很多信息......我还能说什么?我感觉可能是因为我直接在(home)/git/(project)中修改文件...... ?)
最佳答案
git branch -v indicates that my commit was on (no branch). As for the add, I initially commited the changes through Eclipse (with the git plugin)...when I do git add from the command line, it doesn't seem to do anything
这意味着您在 DETACHED HEAD 中模式。
您可以添加和提交,但是从上游存储库的角度来看(即从 GitHub 存储库),没有新的提交准备好被推送。
您可以通过多种方式将本地(分离的 HEAD
)提交回一个分支,然后您就可以推送该分支。
见:
- "Not currently on any branch +
git commit
+ checkout when not in any branch. Did I loose my changes? " - "detached
HEAD
explained "。 - "Git: How can I reconcile detached
HEAD
with master/origin? " - "Git Lesson: Be mindful of a detached head "
- "Git Tip of the Week: Detached Heads "
OP 提到这篇文章是为了解决这个问题:
"git: what to do if you commit to no branch "
all we need to do is checkout the branch we should have been on and merge in that commit SHA:
请注意,您可以使用 head=$(git rev-parse HEAD)
用脚本记住它,而不是 merge 您以某种方式复制的 SHA1:
参见“git: reliably switching to a detached HEAD and then restore HEAD later, all from a script”。
然后您可以将分离的 HEAD
merge 回正确的分支。
关于git - 无法推送到 github : everything up-to-date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11084515/