I'm using a library (say foo
) in my projects and foo
uses another library (say bar
) where I'm also the maintainer of foo
and bar
.
When I change something in bar
library, I commit the changes in bar
repository with appropriate commit message. However, duplicating that appropriate message in foo
and myproject
is very frustrating so I just commit the changes with update bar
and update foo
messages respectively.
How can I make the git commit
command to propose me the latest submodule commit messages?
CodePudding user response:
This is kind of hacky, but here is a way to commit the submodule change in the superproject using the same commit message as the latest submodule commit (assuming you are using Bash):
GIT_ALTERNATE_OBJECT_DIRECTORIES=.git/modules/<submodule-name>/objects git commit -C $(git -C path/to/submodule log --format=%h -1)
This runs git log
in the submodule to get the hash of the latest commit, and then uses GIT_ALTERNATE_OBJECT_DIRECTORIES
to temporarily add the submodule object directory as an alternate to the superproject, such that Git can go read the submodule commit message and use it for the superproject commit.
CodePudding user response:
You would not need to duplicate anything if bar
was declared as a submodule inside foo
repository.
cd /path/to/foo
git submodule add /url/to/bar
cd bar
# add and commit with proper message
git push
cd ..
git add bar
git commit -m "update bar"
The point is: you don't need to duplicate bar commit message, since the very bar
repository is in foo
, and you can directly see the bar
file history, with its original commit message, in foo/bar
.