The project has the main branches of develop
and stable
. In some cases, branches of each individual feature were created from develop
, and in some from stable
, but now it was necessary to find out about one of the old features, from which branch it was created. How can I do that?
|
1 answer
As such, there is no built-in solution to this problem in git, but by combining git with bash you can find several potential solutions to the problem:
git branch --contains develop | grep "brach_name"
git branch --contains develop | grep "brach_name"
- this command will first find all the branches created from develop, then use grep to filter it in search of the desired branch. If the specified branch is not among the branches created from develop, the output will be empty, otherwise the branch name itself will be displayed. At the same time, it is not necessary to switch to the desired branch.The option is more complicated:
git show-branch -a \ | grep '\*' \ | grep -v `git rev-parse --abbrev-ref HEAD` \ | head -n1 \ | sed 's/.*\[\(.*\)\].*/\1/' \ | sed 's/[\^~].*//'
We display a list of all branches in general, then, using console magic, we are looking for the parent of the branch. Demands transition to a branch for which we look for the parent.
I’ll just say that the solutions were checked exclusively on mac OS, but given the similarity of bash with Unix / Linux, it should also work without changes. Under Windows you can easily make similar commands. More information and solutions can be found in this question on SO.
|
git log --graph --all
or in some graphical git-viewer and eyes to understand. Usually it is visible in the graph, but it is difficult to formalize the conditions - Alexey