在 GIT 中撤消结账
使用 MSYSGIT 历史浏览器,我签出了特定的提交。 这是一个错误 - 我试图查看这些文件并认为我必须检查它们才能看到它们。
从那时起,我无法再将任何提交推送到我的远程存储库(在 GITHub 上)。我有点理解,虽然不完全理解。 [我承认不完全理解结帐是如何工作的,请对菜鸟温柔点。]
我如何撤消结帐并使事情恢复到之前的状态?
如果我右键单击“签出”提交,我会看到“删除此分支”的选项。这会删除该提交的文件[坏]还是只是撤消签出?我是不是找错了树?
Using the MSYSGIT history browser, I checked-out a particular commit.
This was a mistake - I was trying to view the files and thought I had to check them out to see them.
Since then, I have been unable to push any more commits to my remote repo (on GITHub). Which I somewhat understand, though not entirely. [I admit to not fully understand how checkout works, please be gentle on a noob.]
How do I undo that checkout and get things back to the state they were in before?
If I right click on the 'checked out' commit, I get the option to 'remove this branch'. Will that delete the files of that commit [bad] or just undo the check out? Am I barking up the wrong tree?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的理解是,您不小心签出了较早的提交,然后在您想要保留的提交之上进行了新的提交。首先,确保您有指向当前工作的指针:
然后,检查您之前的位置:
希望这将使您回到主线分支,并且可以像平常一样推送到 GitHub。如果您想提取所做的更改,则可以合并并(一旦您满意)删除临时分支:
My understanding is that you accidentally checked out an earlier commit, and then made fresh commits on top of that which you'd like to keep. First, ensure you have a pointer to your current work:
Then, checkout where you were before:
Hopefully this will put you back on your mainline branch and you can push to GitHub as normal. If you then want to pull in the changes you made, you can then merge and (once you're happy) delete the temporary branch:
用 C++ 术语来说,分支基本上就是一个指针。
您可能想尝试将分支移动到指向不同的提交。为此,请使用 git reset 。
这不会删除提交,但它确实使
mybranch
“指向”mypreviouscommit
。因此,mypreviouscommit
中的任何内容都将存在于master
中。A branch is basically a pointer, in C++ terms.
You may want to try moving your branch to point to a different commit. Use
git reset
for that.This doesn't delete the commit, but it does make
mybranch
"point to"mypreviouscommit
. So, whatever was there atmypreviouscommit
will be there atmaster
.如果您不介意丢失自上次拉取 GitHUB 以来所做的所有更改,您可以简单地删除您的目录并
创建一个全新的目录。
If you don't mind loosing all the changes you've made since the last pull to GitHUB, you can simply delete your directory and
on a fresh, new one.