gpt4 book ai didi

git - 如何有效地导航 Git 存储库以跟踪项目开发?

转载 作者:太空狗 更新时间:2023-10-29 13:55:39 25 4
gpt4 key购买 nike

我正在尝试了解在 git 存储库中开发的一个相对较新但非常重要的工具。

代码中没有太多文档,但到目前为止,存储库已经收到 <100 次提交,如果我这样做,我可以看到自己更好地理解发生了什么:

  1. checkout 第一次提交;看一些代码
  2. checkout 说 ~5-6 以后提交;看看它是如何变化的
  3. 冲洗并重复#2 直到我是最新的

.. 而不是现在只查看 所有 master 的 HEAD 代码,这要复杂得多。

我的想法的问题是,一旦我 git checkout $commit_1,我就进入了一个分离的头部状态,所以要“向上”到任何更新的提交,我必须 git checkout master 再次,然后按照我的方式进行我想要的提交。有没有更方便的方法来做到这一点?即检查一个旧的提交,然后让 git 向我显示更新的提交并移动到其中一个。

最佳答案

无需一直再次检查 master,或在纸上潦草地记下大量 SHA-1。在任何阶段,您都可以运行

git log --oneline --decorate --graph master

为方便起见,您可能需要像许多 Git 用户一样定义以下别名:

git config alias.lg "log --oneline --decorate --graph"

那么上面的命令就变成了

git lg master

这将输出你的 master 分支的整个祖先的日志(尽管是简洁的形式),无论你在提交图中“在哪里”。

通过相应的短 SHA-1 哈希,这是一种很好的方式来了解您的方位并确定您接下来要 checkout 或检查的提交。请注意,使用 --decorate 标志会显示您所在的位置 (HEAD)。

例子

这是我浏览我自己的 Git 存储库之一的示例:

$ git branch
* master
$ git tag
v0.1
v0.2
v0.3
$ git checkout v0.3
Note: checking out 'v0.3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at cfc71e4... mention compatibility with subset of Octave syntax
$ git log --oneline --decorate --graph master
* 73ec762 (origin/master, origin/HEAD, master) improve brace style
* ffc8d67 remove superfluous word; delete trailing whitespace
* 3f8b8db remove obsolete comment about mcode
* f9f9fd0 remove .DS_Store file that was accidentally added
* cc855ab clarify description of mlonlyheader option
* 7553ccf change contact email
* 4d860e9 correct remarks on shell-escape and backtick
* 9a2ef02 corrected typo in Tips & tricks
* f0badb5 minor improvements in documentation
* cfc71e4 (HEAD, tag: v0.3) mention compatibility with subset of Octave syntax
* 7db2c88 Preventive bugfix: replace \toks@ by \toks@mlpr
* 01fdc43 delete OS-specific files from .gitignore
...

关于git - 如何有效地导航 Git 存储库以跟踪项目开发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27839804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com