2

There is a point in the Git Flow model that I don't quite get.

Once work has been done on a certain feature branch feature/foo, and it is merged on develop, and feature/foo has been deleted, there is no further trace that the commits were done inside the feature/foo branch (see this question).

Sometimes, however, it can be useful to keep track of this information, notably for traceability. Imagine that a branch was created following the opening of a ticket on an issue tracker. I would like to be able to see, preferably with git log, what work was done on this branch, even after it was deleted.

Essentially, I am asking if it possible to obtain with git log the same kind of information that one can find on the closed issues page on a source-code sharing website, such as Github.

It seems to me that without prefixing each commit message (either manually, or through a hook) by the name of the feature branch, there is no easy way.

Community
  • 1
  • 1
Benjamin Audren
  • 374
  • 2
  • 16

2 Answers2

2

You don't have to prefix each commit with the name of the branch. Rather, use the power of git:

git log --all --source --pretty=oneline --graph

will show you a graph of commits, and for each branch you can see with the name of the merge commit what branch was merged into your develop branch.

edi9999
  • 19,701
  • 13
  • 88
  • 127
  • While this is very nice for a simple and short history, it becomes impractical if you deal with a repository with ten regular devs, several feature branches created/merged per day. How do you find back the work done on a certain branch without scrolling hours on the `git log` graph? – Benjamin Audren Aug 04 '15 at 11:28
  • maybe you can do `git log --all --source --pretty=oneline --graph | less` , and then search for the branch name using `/` and your search terms – edi9999 Aug 04 '15 at 11:32
  • The branch name will be gone from the history - that's the whole problem. As discussed in the other answer, I think the right thing to do, as suggested by @gaurav-tiwari, is to create a tag of the branch on deletion. Thanks for your help anyway. – Benjamin Audren Aug 06 '15 at 06:47
  • The branch name is in the name of the merge commit. – edi9999 Aug 06 '15 at 07:05
  • Not necessarilly - I often write a short description of the feature instead of the default message, as I find it clearer. But I agree, a hook that would either write a tag, or add the name inside the commit message would work. Though I find the tag would provide less visual polution when reading the git log. – Benjamin Audren Aug 06 '15 at 07:43
1

Use gitk for that merge commit and it will show which commits are coming from your feature branch.

Or you can use git log --graph --abbrev-commit --decorate --date=relative --all <merge commit>

Gaurav Tiwari
  • 362
  • 2
  • 7
  • So there are still two commands to issue, one to find the merge commit corresponding to the name of the branch (from [there](http://stackoverflow.com/a/7124949/4795601), and then your `git log` option. It also implies keeping the merge commit message *as is*, to keep the reference of the branch's name. I was looking for a one-liner, but this of course be one-lined - assuming the merge-commit message was not modified. – Benjamin Audren Aug 04 '15 at 11:34
  • Yeah you can keep your merge commit messages as they are. Additionally to make it easier you can also have a hook to tag the merges and you can annotate the tag with branch name. This will make it easier to find the merge commit for you – Gaurav Tiwari Aug 04 '15 at 11:45
  • Also as a not so efficient hack you can write a hook to tag your branch before it is deleted. This means whenever you do `git log ` you always get the log for your branch. This is no better than retaining your branch – Gaurav Tiwari Aug 04 '15 at 11:53
  • Why do you say that it is no better than retaining the branch? As long as you use a lightweight tag, it *costs* nothing, right? And why is this not efficient? The difference between your two comments is simply that either the merge commit or the last significant one is tagged with the branch's name, no? – Benjamin Audren Aug 04 '15 at 12:04
  • Branch and tag are technically same as they just represent a commit object. A tag is no more lighter in weight than a branch. The difference us that tags reside in refs/tags while branches are in refs/head. In simpler terms they are just pointers to a commit in git. Tagging will however allow you a track in case you go ahead to delete your topic branch. This can be easily implemented using a git update hook – Gaurav Tiwari Aug 04 '15 at 18:04
  • Ok, thanks, I guess this answers the question: have an git update hook to automatically tag topic branches on deletion, to be able to recover it quickly. Could you update your answer in this direction, and I will then accept it? Thanks for your help. – Benjamin Audren Aug 06 '15 at 06:45