我如何有效地导航 Git 存储库以跟踪项目开发?
How can I efficiently navigate a Git repo to follow project development?
我正在尝试了解在 git 存储库中开发的一个相对较新但非常重要的工具。
代码中没有太多文档,但到目前为止,存储库已经收到了 <100 次提交,如果我这样做,我可以看到自己更好地理解发生了什么:
checkout
第一次提交;看一些代码
checkout
说 ~5-6 稍后提交;看看它是如何变化的
- 冲洗并重复#2 直到我是最新的
.. 而不是现在只看 all master 的 HEAD 代码,这要复杂得多。
我的想法的问题是,一旦我 git checkout $commit_1
,我就会进入一种分离的头脑状态,所以要 "up" 进行任何更新的提交,我必须 git checkout master
再次,然后按照我的方式进行我想要的提交。有没有更方便的方法来做到这一点?即检查一个旧的提交,然后要求 git 向我展示较新的提交并移动到其中一个。
从 git log
中决定哪些提交是感兴趣的。记下他们的 SHA,然后检查它们。不用每次都被师傅拦着
示例:
$ git checkout 315e25
Note: checking out '315e25'.
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 315e25a... 85192566 - Use Linker js namespace for verifying link
07:35:55 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker (detached from 315e25a)
$ git checkout d93b9c
Previous HEAD position was 315e25a... 85192566 - Use Linker js namespace for verifying link
HEAD is now at d93b9c7... 85192548 - Use Linker js domain for show group members
07:36:13 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker (detached from d93b9c7)
$
检查完提交历史和各种感兴趣的提交后,您可以return掌握:
$ git checkout master
Previous HEAD position was d93b9c7... 85192548 - Use Linker js domain for show group members
Switched to branch 'master'
07:37:37 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker master
$ g
On branch master
nothing to commit, working directory clean
您还可以使用相对编号逐步执行 Zeeker 评论中详述的 SHA。
无需一直检查 master
,或在纸上潦草地记下大量 SHA-1。在任何阶段,您都可以运行
git log --oneline --decorate --graph master
为方便起见,您可能需要定义以下别名,许多 Git 用户都这样做:
git config alias.lg "log --oneline --decorate --graph"
那么上面的命令就变成了
git lg master
这将输出您的 master
分支的整个祖先的日志(尽管是简洁的形式),无论提交图中 "where you are" 是什么。
通过相应的短 SHA-1 哈希,这是一种很好的方式来了解您的方位并确定您接下来要签出或检查的提交。请注意,使用 --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 存储库中开发的一个相对较新但非常重要的工具。
代码中没有太多文档,但到目前为止,存储库已经收到了 <100 次提交,如果我这样做,我可以看到自己更好地理解发生了什么:
checkout
第一次提交;看一些代码checkout
说 ~5-6 稍后提交;看看它是如何变化的- 冲洗并重复#2 直到我是最新的
.. 而不是现在只看 all master 的 HEAD 代码,这要复杂得多。
我的想法的问题是,一旦我 git checkout $commit_1
,我就会进入一种分离的头脑状态,所以要 "up" 进行任何更新的提交,我必须 git checkout master
再次,然后按照我的方式进行我想要的提交。有没有更方便的方法来做到这一点?即检查一个旧的提交,然后要求 git 向我展示较新的提交并移动到其中一个。
从 git log
中决定哪些提交是感兴趣的。记下他们的 SHA,然后检查它们。不用每次都被师傅拦着
示例:
$ git checkout 315e25
Note: checking out '315e25'.
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 315e25a... 85192566 - Use Linker js namespace for verifying link
07:35:55 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker (detached from 315e25a)
$ git checkout d93b9c
Previous HEAD position was 315e25a... 85192566 - Use Linker js namespace for verifying link
HEAD is now at d93b9c7... 85192548 - Use Linker js domain for show group members
07:36:13 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker (detached from d93b9c7)
$
检查完提交历史和各种感兴趣的提交后,您可以return掌握:
$ git checkout master
Previous HEAD position was d93b9c7... 85192548 - Use Linker js domain for show group members
Switched to branch 'master'
07:37:37 durrantm Castle2012 /home/durrantm/Dropnot/_/rails_apps/linker master
$ g
On branch master
nothing to commit, working directory clean
您还可以使用相对编号逐步执行 Zeeker 评论中详述的 SHA。
无需一直检查 master
,或在纸上潦草地记下大量 SHA-1。在任何阶段,您都可以运行
git log --oneline --decorate --graph master
为方便起见,您可能需要定义以下别名,许多 Git 用户都这样做:
git config alias.lg "log --oneline --decorate --graph"
那么上面的命令就变成了
git lg master
这将输出您的 master
分支的整个祖先的日志(尽管是简洁的形式),无论提交图中 "where you are" 是什么。
通过相应的短 SHA-1 哈希,这是一种很好的方式来了解您的方位并确定您接下来要签出或检查的提交。请注意,使用 --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
...