我是否需要在 Git 中提交,何时应该这样做,以及如何恢复到旧版本?
我一直在关注 Git 教程,但对一些具体问题有点困惑。我现在需要使用版本控制的主要原因只是为了在我犯了错误并且不知道如何消除错误时访问项目的以前版本。
只有执行提交语句后版本才会保存在 Git 中,这是真的吗?出于某种原因,我在想,每次你在项目中进行任何更改时,它都会自动添加为存储库中的版本,供你返回。
那么什么时候应该执行commit呢?是不是只有当你认为自己已经取得了很大进展的时候才执行?
如何在 Git 中实际恢复到以前的版本?即命令是什么?
I've been following a tutorial on Git and I'm a bit confused about a few specific issues. The main reason I need to use version control right now is simply to access previous versions of my project if I make a mistake and don't know how to get rid of an error.
Is it true that a version is only saved in Git if you executed a commit statement? For some reason, I was thinking that every time you make any change in your project it would automatically be added as a version in your repository for you to go back to.
So when should you execute commit? Is it only when you think you've made a good bit of progress?
How do you actually revert to a previous version in Git? i.e. what's the command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
1.使用 Git(与 SVN、Bazzar 或其他相同),您需要提交,以便保存版本 - 这样,git 只跟踪您认为足够好的版本。
2. 当我得到一些可以正常工作的东西时,我倾向于做出承诺——至少在主分支上工作时。
如果我正在开发一个临时分支,专门为开发新功能/修复错误而创建,那么我几乎可以随时提交,以保存工作的当前状态。
3. 您应该查看以下页面: Git 中的撤销 - 重置、签出和恢复
1. With Git (same with SVN, or Bazzar, or others), you need to commit so a version is saved -- this way, git only keeps track of the versions you considered as good enough.
2. I tend to commit when I've got something that works OK -- at least when working on the main branch.
If I'm working on a temporary branch, created specifically to develop a new feature / fix a bug, then I commit pretty much whenever I want, to save the current state of my work.
3. You should take a look at the following page : Undoing in Git - Reset, Checkout and Revert
[commit-ref]
是您想要的版本的哈希值。git checkout [commit-ref] [filename]
.The
[commit-ref]
is the hash value of the version you want.是的。但请继续阅读...
特别是对于 git,每次您认为自己已经进行了一项独立的逻辑更改时都进行提交是一个好主意。因此,这种情况应该经常发生——通常每 5 到 30 分钟提交一次。例如,只需克隆 git 的 git 存储库,然后查看一些更有经验的人的工作。
在许多其他 vcs:es 中,您的提交对其他人立即可见,因此通常认为仅在构建或拥有完整功能时进行提交是一种良好的做法。在 git 中,这种粒度级别是由分支处理的,查看您的提交日志的人应该不仅能够看到您做了什么,还能够看到您是如何做到的,例如:
这使得回顾源代码的工具对于调试更加有用。您当然应该尽量避免更改 100 多行的单次提交——它们会将您在源代码上完成的工作变成难以理解的不透明块。
Yes. But read on...
With git specifically, it's a good idea to commit every time you think you have made one self-contained logical change. So this should happen quite a lot -- typically commit between once in 5-30 minutes. For examples, just clone the git repo for git, and look at the work of some of the more experienced people.
In many other vcs:es, where your commits are immediately visible to other people, it's often considered good practise to only commit when it builds, or when you have a complete feature. In git, this level of granularity is handled by branches, and someone viewing your commit log should be able to see not just what you did, but how you did it, eg:
This makes tools that look back on the source much more useful for debugging. You should certainly try to avoid single commits that change 100+ lines -- they turn work you have done on the source into opaque blocks that are hard to understand.