简体   繁体   中英

Git: how do you document development steps before deleting a branch?

As a new-ish Git user, I like to keep merged branches around to serve as a development artifact showing what code and steps solved an issue. Since it seems everyone prefers a clean branch list by deleting branches once that work is finished and committed, what do you use to preserve the development steps for each specific issue?

(I understand that commits remain in the history after branches are deleted. The point is, as long as a branch exists, it's clear which commits it contains. Once a branch is merged back into master and deleted, all you're left is a long master history. So, when faced with a long history of undifferentiated commits, how do you document your work in order to identify which commits used to be part of a certain branch — which commits implemented what ticket or functionality?)

First of all, as far as I know your Git repository would have to keep alive the feature branches which are merged into the main branch, because they are reachable from the merge commits in that main branch.

That being said, if you really wanted a workflow which maximized the chance of capturing every step taken by a developer, you might not even choose a merge based workflow. Instead, you might choose a rebase workflow, which would promote having a completely linear main branch.

Consider the following scenario:

remote:   A -- B -- C
           \
feature:    D -- E -- F

Doing git rebase remote from the feature branch would result in the following:

remote:   A -- B -- C
                     \
feature:              D' -- E' -- F'

Now, doing git push origin feature would yield a completely linear update of the remote branch:

remote:   A -- B -- C -- D' -- E' -- F'

With a linear history, it is easy to read what happened in a branch. But, using git rebase is more complicated than git merge , which is something to keep in mind.

All commits to any branch are saved in your git repository as hidden branches, regardless of whether you have deleted the branch or not. If you would like to access a branch that you have merged into master - for example - after you have deleted it, you could:

  1. Look into your git log by typing git log
  2. Copy the most recent commit id of the branch you merged with the master (some long hash)
  3. Check out the branch of that commit by typing git checkout <commit id>

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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