【发布时间】:2019-03-02 20:58:34
【问题描述】:
git这里是新手,习惯了subversion:
我已经提交了一些本地更改,现在想要推送,但我得到了:
$ git push
Everything up-to-date
在 Google 快速搜索后,我发现:git push says everything up-to-date even though I have local changes,我认为 太棒了! 并开始遵循已接受答案中的建议:
$ git log -1
#got the hash key
$ git checkout master
M util/logging/cp_logging.cpp
Already on 'master'
Your branch is up-to-date with 'origin/master'.
#Now I got nervous and verified with git status
#and git diff that my changes were still there
#just for safety I did a
$ git diff >save.patch
#followed by(as recommended):
$ git reset --hard 579823db25d2a821c2940608e9cb8122c2779b37
HEAD is now at 579823d Merge remote-tracking branch 'upstream/master'
#then I did a
$ git status
# and realized that my changes were gone!
如何让我的更改(幸运的是保存 save.patch)回到我的本地工作副本,然后从这里将更改推送到在线存储库?我的更改是否应该已经提交到我的本地仓库中(就像我之前所做的 git commit 一样)?
【问题讨论】:
-
git apply save.patch。然后git reset --hard相当于 git 的 nuke,因此当您在工作树周围进行更改时请小心使用。如果它是您正在玩的已提交内容,您可以使用各种技巧将其从硬重置中恢复,但对于尚未提交的内容则不能这样说。