Git 恢复、签出和重置傻瓜式教程

发布于 2024-12-16 18:30:35 字数 186 浏览 2 评论 0原文

抱歉,这三个 git 命令正在考验我的智力。

是否可以为所有新手建立一个群组 wiki 来涵盖这三个 git 命令?我想要学习的是如何将文件和项目恢复或回滚到之前的状态。

由于我没有使用 subversion 或其他集中式版本控制软件的经验,因此没有必要参考它们如何以不同的方式做事,而且常常令人困惑。

谢谢。

Sorry, but this trio of git commands is taxing my intelligence.

Is it possible to set up a group wiki for total newbies to cover these three git commands? What I am trying to learn is how to restore or rollback files and projects to a prior state.

As I have no experience with subversion or other centralized version control software, reference to how they did things differently is unnecessary and often confusing.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

夏了南城 2024-12-23 18:30:35

您提到的所有资源都很受欢迎,但我很惊讶您没有发现它们有帮助。每个命令的手册页可能是最具描述性的资源,但无可否认是枯燥和密集的。以下是这三个命令之间差异的简要总结:

  • git revert 采用树状结构并创建一个新的提交,撤消给定提交中所做的更改

  • git checkout 的作用就是:签出树形结构。如果您传递分支名称,您将移动到该分支的 HEAD ,如果您传递非 HEAD 提交或标记,您将输入“分离” HEAD”状态。无论如何,您的工作树现在将与提交时相同(这里存在一些未跟踪/新文件的边缘情况)。

  • git reset 采用树状结构,并删除直到(但不包括)给定提交的所有提交,但不更改任何文件的当前状态。也就是说,提交消失了,但您的工作树仍处于相同状态。传递 --hard 也会将文件恢复到状态。

(是的,树状结构是真实存在的

All the resources you mentioned are quite popular, and I'm surprised you didn't find them helpful. The man pages for each of those commands are probably the most descriptive resource, but are admittedly dry and dense. Here is a brief summary of the difference between the three commands:

  • git revert takes a treeish and creates a new commit undoing the changes made in the given commit

  • git checkout does just that: checks out a treeish. If you pass a branch name, you'll move to the HEAD of that branch, if you pass a non-HEAD commit or tag, you'll enter a "detached HEAD" state. Regardless, your working tree will now be the same as it was at the commit (there are some edge cases here with untracked/new files).

  • git reset takes a treeish, and erases all the commits up to (but not including) the given commit, but without altering the current state of any of the files. That is, the commits are gone, but your working tree remains in the same state. Passing --hard also puts the files back to the state.

(Yes, a treeish is a real thing)

放肆 2024-12-23 18:30:35

是否可以为所有新手建立一个群组 wiki 来涵盖这三个 git 命令?

诚实地?可能是的。肯定是,也许是。不过我从来没有建立过维基百科,所以我不知道我是否能够帮助你。 :P

不过,严肃地说,如果您以前没有看过这个链接,它可能会对您有所帮助: http://wiki.freegeek.org/index.php/Git_for_dummies

另外,如果您还没有解析这个问题,请查看它:Git 初学者:权威的实用指南

Is it possible to set up a group wiki for total newbies to cover these three git commands?

Honestly? Probably, yeah. Definitely, maybe. I've never set up a wiki, though, so I don't know if I'd be able to help you. :P

In all seriousness, though, this link might help you if you haven't seen it before: http://wiki.freegeek.org/index.php/Git_for_dummies

Additionally, check out this question if you haven't parsed it already: Git for beginners: The definitive practical guide

無處可尋 2024-12-23 18:30:35

http://progit.org/2011/07/11/reset.html帮助我了解结账和重置之间的相似点和差异。恢复是一个不同的故事,它创建一个新的提交,取消另一个提交。

http://progit.org/2011/07/11/reset.html helped me a lot in seeing the similarities and differences between checkout and reset. Revert is a different story that creates a new commit, canceling out another.

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