转到特定修订版

发布于 2024-12-06 10:25:17 字数 82 浏览 5 评论 0原文

我克隆了某个项目的 Git 存储库。我可以将文件转至初始状态,然后在查看文件时转到修订版 2、3、4 ...最新版本吗?我想了解一下该项目的进展情况。

I cloned a Git repository of a certain project. Can I turn the files to the initial state and when I review the files go to revision 2, 3, 4 ... most recent? I'd like to have an overview of how the project was evolving.

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

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

发布评论

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

评论(7

心头的小情儿 2024-12-13 10:25:17

在执行此命令之前,请记住,它将使您处于分离头部状态

使用 git checkout来签出特定的提交。

其中 是提交唯一编号 (SHA-1 哈希值),您可以使用 git log 获取。

处于分离头状态后,以下是一些选项:

  • 将文件或所需的更改复制到 Git 文件夹外部的文件夹中,签出您需要的分支 git checkout并替换文件
  • 创建一个新的本地分支 git checkout -b;

注意:要“撤消”(从)分离头状态返回,只需使用:

git checkout (其中 code> 是例如 master)。

Before executing this command, keep in mind that it will leave you in a detached head status.

Use git checkout <sha1> to check out a particular commit.

Where <sha1> is the commit unique number (SHA-1 hash value) that you can obtain with git log.

Here are some options after you are in the detached head status:

  • Copy the files or make the changes that you need to a folder outside your Git folder, check out the branch where you need them git checkout <existingBranch> and replace files
  • Create a new local branch git checkout -b <new_branch_name> <sha1>

Note: to "undo" (return from) the detached head state, simply use:

git checkout <branch> (where <branch> is e.g. master).

不甘平庸 2024-12-13 10:25:17

要转到特定版本/提交,请运行以下命令。您可以从 git log --oneline -n​​ 10 获取 HASH-CODE:

git reset --hard HASH-CODE

注意 - 重置到特定版本/提交后,您可以运行 git pull - -rebase,如果你想恢复所有被丢弃的提交。

To go to a particular version/commit, run the following commands. You can get HASH-CODE from git log --oneline -n 10:

git reset --hard HASH-CODE

Note - After resetting to a particular version/commit, you can run git pull --rebase, if you want to bring back all the commits which are discarded.

马蹄踏│碎落叶 2024-12-13 10:25:17

您可以使用 gitk 等工具获取项目历史记录的图形视图。只需运行:

gitk --all

如果您想签出特定分支:

git checkout <branch name>

对于特定提交,请使用 SHA-1 哈希而不是分支名称。 (请参阅Git 社区书籍中的 Treeishes,这是一本好书,可以查看用于导航树的其他选项。)

git log 还有一整套选项可以显示详细或摘要历史记录。

我不知道有什么简单的方法可以在提交历史记录中前进。具有线性历史的项目可能并不常见。像 SVN 或 CVS 那样的“修订”的想法在 Git 中并没有很好地体现。

You can get a graphical view of the project history with tools like gitk. Just run:

gitk --all

If you want to checkout a specific branch:

git checkout <branch name>

For a specific commit, use the SHA-1 hash instead of the branch name. (See Treeishes in the Git Community Book, which is a good read, to see other options for navigating your tree.)

git log has a whole set of options to display detailed or summary history too.

I don't know of an easy way to move forward in a commit history. Projects with a linear history are probably not all that common. The idea of a "revision" like you'd have with SVN or CVS doesn't map all that well in Git.

水波映月 2024-12-13 10:25:17

使用提交的 SHA-1 键/哈希值,您可以执行以下操作:

  • < p>首先,找到您想要的特定文件的提交:

    git log -n <# 提交>; <文件名>

    这将根据您的 <# commits> 生成特定文件的提交列表。

    提示:如果您不确定要查找的提交,最好的方法是使用以下命令:git diff < ;commit-SHA1>..HEAD <文件名>。此命令将显示特定文件的当前版本的提交与先前版本的提交之间的差异。

    注意:提交的 SHA-1 密钥在 git log -n 列表中的格式如下:

    <块引用>

    提交

  • 其次,检查所需的版本:

    如果您找到了所需的提交/版本,只需使用命令:git checkout; <文件名>

    这会将您指定的文件版本放置在暂存区域中。要将其从暂存区域中取出,只需使用以下命令:reset HEAD

要恢复到远程存储库指向的位置,只需使用命令:git checkout HEAD <文件名>

Using a commit's SHA-1 key/hash value, you could do the following:

  • First, find the commit you want for a specific file:

    git log -n <# commits> <file-name>

    This, based on your <# commits>, will generate a list of commits for a specific file.

    Tip: if you aren't sure what commit you are looking for, a good way to find out is using the following command: git diff <commit-SHA1>..HEAD <file-name>. This command will show the difference between the current version of a commit, and a previous version of a commit for a specific file.

    Note: a commit's SHA-1 key is formatted in the git log -n's list as:

    commit <SHA1 id>

  • Second, checkout the desired version:

    If you have found the desired commit/version you want, simply use the command: git checkout <desired-SHA1> <file-name>

    This will place the version of the file you specified in the staging area. To take it out of the staging area simply use the command: reset HEAD <file-name>

To revert back to where the remote repository is pointed to, simply use the command: git checkout HEAD <file-name>

夜光 2024-12-13 10:25:17

要获取特定的提交代码,您需要该提交的哈希代码。您可以通过两种方式获取该哈希代码:

  1. GitHub 获取它,GitLab,或 Bitbucket 帐户。
    (它位于您的提交 URL 上,即 github.com/user/my_project/commit/commit_hash_code),或者您可以
  2. git log 并检查您最近在该分支上的提交。它将显示您提交的哈希代码以及您在提交代码时留下的消息。只需复制然后执行 git checkout commit_hash_code

移动到该代码后,如果您想对其进行操作并进行更改,您应该使用 git checkout -b。否则,更改将不会被保留。

To get to a specific committed code, you need the hash code of that commit. You can get that hash code in two ways:

  1. Get it from your GitHub, GitLab, or Bitbucket account.
    (It's on your commit URL, i.e., github.com/user/my_project/commit/commit_hash_code), or you can
  2. git log and check your recent commits on that branch. It will show you the hash code of your commit and the message you left while you were committing your code. Just copy and then do git checkout commit_hash_code

After moving to that code, if you want to work on it and make changes, you should make another branch with git checkout -b <new-branch-name>. Otherwise, the changes will not be retained.

烟花肆意 2024-12-13 10:25:17

我遇到的情况是,我们有一个 master 分支,然后另一个名为 17.0 的分支,在这个 17.0 中有一个提交哈希号,比如“XYZ” 。客户将获得 XYZ 修订版之前的版本。
现在我们遇到了一个错误,需要为该客户解决。因此,我们需要为该客户创建一个单独的分支,直到获得“xyz”哈希值。
我就是这样做的。

首先,我在本地计算机上创建了一个具有该客户名称的文件夹。假设客户名称是“AAA”,
创建该文件夹后,在此文件夹中发出以下命令:

  1. git init
  2. git clone 执行此命令后,您将位于 master 分支上。因此,切换到所需的分支
  3. git checkout 17.0 这会将您带到您的提交所在的分支
  4. git checkout :这将使您的存储库直到该哈希提交为止。查看您的分支机构的名称。它已更改为该提交哈希号。现在为此哈希值指定一个分支名称
  5. gitbranch ABC:这将在您的本地计算机上创建一个新分支。
  6. git checkout ABC
  7. git push origin ABC:这会将这个分支推送到远程存储库,并在 Git 服务器上创建一个分支。
    你完成了。

I was in a situation where we have a master branch, and then another branch called 17.0 and inside this 17.0 there was a commit hash number, say "XYZ". And the customer is given a build till that XYZ revision.
Now we came across a bug and that needs to be solved for that customer. So we need to create a separate branch for that customer till that "xyz" hash value.
So here is how I did it.

First I created a folder with that customer name on my local machine. Say the customer name is "AAA",
once that folder is created, issue the following command inside this folder:

  1. git init
  2. git clone After this command, you will be on the master branch. So switch to the desired branch
  3. git checkout 17.0 This will bring you to the branch where your commit is present
  4. git checkout : This will take your repository till that hash commit. See the name of your branch. It got changed to that commit hash number. Now give a branch name to this hash value
  5. git branch ABC: This will create a new branch on your local machine.
  6. git checkout ABC
  7. git push origin ABC: This will push this branch to the remote repository and create a branch on the Git server.
    You are done.
伤感在游骋 2024-12-13 10:25:17

一种方法是创建对补丁所做的所有提交。检查初始提交,然后在阅读后按顺序应用补丁。

使用 git format-patch,然后使用 git checkout
您应该在目录中获得一堆文件,以四位数字开头,这是补丁。

阅读完修订版本后,只需执行 git apply 即可,该操作应类似于 git apply 0001-* 并进行计数。

Git 手册还给了我这个:

 git show next~10:文档/自述文件

显示文件 Documentation/README 的内容,因为它们在下一个分支的最后 10 次提交中是最新的。

您还可以查看 gitblame filename,它为您提供了一个列表,其中每一行都与提交哈希+作者相关联。

One way would be to create all commits ever made to patches. Check out the initial commit and then apply the patches in order after reading.

Use git format-patch <initial revision> and then git checkout <initial revision>.
You should get a pile of files in your directory, starting with four digits which are the patches.

When you are done reading your revision, just do git apply <filename> which should look like git apply 0001-* and count.

The Git manual also gives me this:

 git show next~10:Documentation/README

Shows the contents of the file Documentation/README as they were current in the 10th last commit of the branch next.

You could also have a look at git blame filename which gives you a listing where each line is associated with a commit hash + author.

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