如何克隆旧的 git-commit(以及更多关于 git 的问题)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1655361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:17:34  来源:igfitidea点击:

how to clone an old git-commit (and some more questions about git)

git

提问by Berschi

I have a git-repository of my project with about 20 commits. I know how to clone the actual commit with git clone,

我的项目有一个 git-repository,大约有 20 次提交。我知道如何克隆实际提交git clone

  • but how can I "clone" an old commit?
  • is there a really good git-GUI (imho qgitis not a good GUI)?
  • what exactly are "branches"?
  • when I want to release 0.1, 0.2 and so on, what is the best way to mark these commits in git?
  • what are the big differences to svn?
  • 但是我怎样才能“克隆”一个旧的提交呢?
  • 是否有一个非常好的 git-GUI(恕我直言qgit不是一个好的 GUI)?
  • 究竟什么是“分支”?
  • 当我想发布 0.1、0.2 等版本时,在 git 中标记这些提交的最佳方法是什么?
  • 与 svn 的最大区别是什么?

回答by VonC

A git repository contains the all history at all time.
So when you are cloning a repository, you are cloning it with its full history, and then, you can make a branch from whatever commit you want:

git 存储库始终包含所有历史记录。
所以当你克隆一个仓库时,你是在克隆它的完整历史,然后,你可以从你想要的任何提交中创建一个分支:

 $ git checkout -b aNewBranch SHA1

with SHA1 representing the commit id from which you want to proceed.

SHA1 表示您要继续的提交 ID。



Branches in Git are just a way to keep track of one path of a DAG (Directed Acyclic Graph)which is the set of commits representing the history of a Git repository.
It is a mere pointer you assign to one of those commits, and it will keep moving along with each new commits.

Git 中的分支只是跟踪DAG(有向无环图)的一个路径的一种方式,DAG(有向无环图)是表示 Git 存储库历史记录的一组提交。
它只是您分配给其中一个提交的一个指针,它会随着每个新提交而继续移动。

branches

分行

See Pro Gitbook for more.

有关更多信息,请参阅Pro Git书籍。



You can mark a specific commit with a tag, which, like a branch, is a mere pointer, but an immutable one (it wont move when you make new commit).
You will use preferably annotatedtags, which are stored as full objects in the Git database. They're checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).

你可以用tag标记一个特定的提交,它和分支一样,只是一个指针,但是一个不可变的指针(当你进行新的提交时它不会移动)。
您最好使用带注释的标签,这些标签作为完整对象存储在 Git 数据库中。它们是校验和的;包含标记者姓名、电子邮件和日期;有标签信息;并且可以使用 GNU Privacy Guard (GPG) 进行签名和验证。



The "Graphical Interfaces" section of InterfacesFrontendsAndToolspage on Git Wiki lists the various GUI for Git at the moment.

Git Wiki 上InterfacesFrontendsAndTools页面的“图形界面”部分列出了目前 Git 的各种 GUI。



You will see many questions about the difference between Git and SVN: see my answer(or this one) for example.
My most complete answer about the fundamental differences between Git and SVN is here:
"which of the two is better:git or SVN".

您会看到许多关于 Git 和 SVN 之间区别的问题:例如,请参阅我的答案(或这个答案)。
关于 Git 和 SVN 之间的根本区别,我最完整的答案是:
“两者中哪一个更好:git 或 SVN”

回答by cdmo

There are a few questions in this post, here is my take on some answers:

这篇文章有几个问题,以下是我的一些答案:

First, to "clone" a previous commit, you can do something like this:

首先,要“克隆”先前的提交,您可以执行以下操作:

git clone REPO_URL
git checkout HEAD~1 // checks out the last commit's first parent

Use ~1to access the last commit's first parent, and increment the number to get the parent's parent and so on. More on tilde and caret notation.

使用~1访问最后一次提交的第一父,并增加数量来获得父母的父母等。更多关于波浪号和插入符号的信息

The two commands above will put you in a detached HEAD state, which may or may not be important based on context. For example, it isn't important if you are cloning as part of your deployment scripts and all you care about is accessing a previous commit (say, as part of a rollback strategy).

上面的两个命令将使您处于分离的 HEAD 状态,根据上下文,这可能重要也可能不重要。例如,如果您将克隆作为部署脚本的一部分并且您所关心的只是访问以前的提交(例如,作为回滚策略的一部分),这并不重要。

If you need to begin work from this point in history, you can run

如果你需要从历史的这个点开始工作,你可以运行

git checkout -b NEW_BRANCH_NAME

A good git GUI? For me SourceTreeis the best.

一个好的 git GUI?对我来说SourceTree是最好的。

What are branches? In my own words, a branch is just a very easy way to pivot. Say you are working on one branch, masterand you want to try an experiment. Easy, just git checkout -b experimentand you are quickly in a safe place to break stuff.

什么是分支?用我自己的话来说,分支只是一种非常简单的枢轴方式。假设您正在一个分支上工作,master并且您想尝试一项实验。简单,公正git checkout -b experiment,您很快就可以在一个安全的地方打破东西。

What's different between git and svn?

git 和 svn 有什么不同?

git is a distribute version control system. svn is not. Also, branching (mentioned above) is easier in git.

git 是一个分布式版本控制系统。svn 不是。此外,分支(上面提到的)在 git 中更容易。

For tagging, I don't know if there's "One True Way" (is there ever?) but just explore the git tagcommand. One great thing about git is how easy it is to clone a duplicate of your repo on your local computer (or wherever) and do whatever you want to it and see what happens. If you mess something up, just delete the directory. So, you can experiment with git tagin some testing directory and see what you like.

对于标记,我不知道是否有“一种正确的方式”(有过吗?),但只是探索git tag命令。关于 git 的一件好事是,在本地计算机(或任何地方)上克隆存储库的副本是多么容易,然后做任何你想做的事情,看看会发生什么。如果你搞砸了,只需删除目录。所以,你可以git tag在一些测试目录中进行试验,看看你喜欢什么。