简体   繁体   English

Git 获取我所在的分支的历史记录

[英]Git get history of branches that i was in

I need to see the history of branches that i was using.我需要查看我正在使用的分支的历史记录。 For example i have 4 branches: master, b-1, b-2, b-1-1.例如,我有 4 个分支:master、b-1、b-2、b-1-1。 Thе branch "b-1-1" is child of branch "b-1".分支“b-1-1”是分支“b-1”的子分支。 First i was at master branch, then at branch b-1, then at branch b-1-1, then at branch b-2, then again at b-1-1.首先,我在 master 分支,然后在分支 b-1,然后在分支 b-1-1,然后在分支 b-2,然后再次在 b-1-1。 The history of my used branches would look like this:我使用过的分支的历史如下所示:

  • b-1-1 b-1-1
  • b-2 b-2
  • b-1-1 b-1-1
  • b-1 b-1
  • master掌握

Is it possible to do so in git?是否可以在 git 中这样做? If yes, then how?如果是,那么如何? I have tried to check the git log but it is not what i am searching for.我试图检查 git 日志,但这不是我要搜索的。

Take a look at git reflog to inspect the history of HEAD positions.查看git reflog以检查HEAD位置的历史记录。

There's also git reflog <branch> for the history of a specific branch.还有git reflog <branch>用于特定分支的历史记录。

Check documentation here .在此处查看文档。

I don't think you can see which branch were checked out and in which order in a sense that you've formulated in the question .我不认为你可以看到哪个分支被检出以及在你在问题中制定的某种意义上。 Branch is a pointer and this pointer can change only if you do commit. Branch 是一个指针,这个指针只有在你提交时才能改变。

For example, if you:例如,如果您:

  • checkout the existing branch branch ( git checkout abc )签出现有的分支分支( git checkout abc
  • see its log ( git log -n 10 )查看它的日志( git log -n 10
  • checkout another existing branch xyz ( git checkout xyz )结帐另一个现有分支 xyz ( git checkout xyz )

Then git won't remember that you were checking out the abc branch然后 git 不会记得你在检查abc分支

Having said that, you can see the commits that you've done during, say last 3 days with this command:话虽如此,您可以使用以下命令查看您在此期间所做的提交,例如最近 3 天:

git log --since="3 days ago" --author=<HERE_COMES_YOUR_NAME_IN_GIT> --all

This --since parameter can be really flexible, 1 day ago , exact time, 1 week ago are all possible values, check out the documentation and also this SO thread这个--since参数可以非常灵活, 1 day ago ,确切时间, 1 week ago都是可能的值,查看文档和这个SO线程

Another interesting option is using (in its the most basic form): git for-each-ref --sort=-committerdate refs/heads/另一个有趣的选项是使用(以最基本的形式): git for-each-ref --sort=-committerdate refs/heads/

This command will print all commits in all branches in the descending order.此命令将按降序打印所有分支中的所有提交。 There is already thread in SO about this and it provides way more options of possible usage of this command than I can do so please check that out as well. SO中已经有关于这个的线程,它提供了比我能做的更多的可能使用这个命令的选项,所以请检查一下。

This invocation of git reflog with some grep filtering seems to be working for me:使用一些grep过滤对git reflog的调用似乎对我有用:

git reflog | grep checkout | grep -o 'to .*$' | grep -o ' .*$' | less

For example:例如:

 b2
 master
 b1
 master
 b2
 b1
 b2
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM