首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何有效地导航Git回购以跟踪项目开发?

如何有效地导航Git回购以跟踪项目开发?
EN

Stack Overflow用户
提问于 2015-01-08 12:07:57
回答 2查看 421关注 0票数 3

我正在尝试理解git存储库中正在开发的一个相对较新但并不简单的工具。

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

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

。。而不是现在只看主人的头上的所有代码,这要复杂得多。

我的想法的问题是,一旦我git checkout $commit_1,我就进入了一个分离的头状态,因此,为了“向上”到任何新的提交,我必须再次git checkout master,然后工作到我想要的提交。有更方便的方法吗?也就是说,检查一个旧的提交,然后要求git向我展示更新的提交并移到其中的一个。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-08 13:18:58

不需要随时检查master,也不需要在一张纸上乱写大量的SHA-1。在任何阶段,您都可以运行

代码语言:javascript
复制
git log --oneline --decorate --graph master

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

代码语言:javascript
复制
git config alias.lg "log --oneline --decorate --graph"

然后上面的命令简单地变成

代码语言:javascript
复制
git lg master

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

这是一个很好的方法,以获得您的方位,并确定谁提交您想要检查或检查下,通过其相应的简短的SHA-1散列。注意,使用--decorate标志可以显示您所在的位置(HEAD)。

示例

下面是我在自己的Git存储库中导航的一个示例:

代码语言:javascript
复制
$ 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
...
票数 4
EN

Stack Overflow用户

发布于 2015-01-08 12:36:56

git log中决定是否有兴趣提交。把他们的SHA记下来,然后检查一下。不用每次都来拜访师父。

示例:

代码语言:javascript
复制
$ 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)
$ 

当您签出提交历史记录和各种感兴趣的提交时,您可以返回给主人:

代码语言:javascript
复制
$ 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

您还可以使用相对编号来逐步通过SHA,如Zeeker的评论中所详细介绍的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27839804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档