在 GIT 中撤消结账

发布于 2024-08-03 04:07:24 字数 256 浏览 4 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初心未许 2024-08-10 04:07:24

我的理解是,您不小心签出了较早的提交,然后在您想要保留的提交之上进行了新的提交。首先,确保您有指向当前工作的指针:

git checkout -b newbranch

然后,检查您之前的位置:

git checkout master

希望这将使您回到主线分支,并且可以像平常一样推送到 GitHub。如果您想提取所做的更改,则可以合并并(一旦您满意)删除临时分支:

git merge newbranch
git branch -d newbranch

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:

git checkout -b newbranch

Then, checkout where you were before:

git checkout master

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:

git merge newbranch
git branch -d newbranch
素手挽清风 2024-08-10 04:07:24

用 C++ 术语来说,分支基本上就是一个指针。

您可能想尝试将分支移动到指向不同的提交。为此,请使用 git reset 。

git checkout mybranch
git reset mypreviouscommit

这不会删除提交,但它确实使 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.

git checkout mybranch
git reset mypreviouscommit

This doesn't delete the commit, but it does make mybranch "point to" mypreviouscommit. So, whatever was there at mypreviouscommit will be there at master.

三人与歌 2024-08-10 04:07:24

如果您不介意丢失自上次拉取 GitHUB 以来所做的所有更改,您可以简单地删除您的目录并

git clone ...

创建一个全新的目录。

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

git clone ...

on a fresh, new one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文