问题
I've been working on a system to keep a BRANCH_DESCRIPTION file whenever I create a topic branch in git. Like others have mentioned, I too sometimes forget what I created a branch for, even though I try to give it a descriptive name.
I have been primarily working off the SO question How do I tell git to always select my local version for conflicted merges on a specific file?, but I've run into a case where the custom merge driver does not get called, so the file from the topic branch being merged in overwrites the local branch. For example:
git checkout master
echo "mainline" > BRANCH_DESCRIPTION
git add BRANCH_DESCRIPTION
git commit -m'Added BRANCH_DESCRIPTION file'
git checkout -b topic_branch
echo "this branch is used to fix the bug where [...]" > BRANCH_DESCRIPTION
git commit -m'Updated BRANCH_DESCRIPTION'
[code, code, code ...]
[git, git, git ...]
git checkout master
git merge --no-ff topic_branch
At this point BRANCH_DESCRIPTION will simply be overwritten since the master branch's description has not changed regardless if a custom merge driver has been setup for the file.
Any ideas?
回答1:
Try using git notes
for this purpose.
In your branch do git notes add -m "this branch is for blah blah"
Then write a post-commit in your repo with the following:
#!/bin/sh
git notes show HEAD~1
git notes copy HEAD~1 HEAD
Additionally add a git notes remove HEAD~1
if you want.
Use git notes show
to see what the branch is for.
回答2:
Git now supports this by running git branch --edit-description
This answer has a nice writeup
来源:https://stackoverflow.com/questions/7226953/branch-descriptions-in-git-continued