Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

git commit using both verbose and message flags not working

I have a script that runs in a build pipeline which makes git commits.

I want the commit message to be fixed with no prompt and also the commit to be verbose.

When I use this format of command, the commit is not verbose:

git commit -v -m 'commit message' git commit --verbose -m 'commit message'

What is the right correct way to structure this so I can supply the commit message to a verbose commit in one line?

question from:https://stackoverflow.com/questions/65886270/git-commit-using-both-verbose-and-message-flags-not-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is no concept of a "verbose commit" in git. The -v option makes the process of committing more verbose, in that it shows the diff in the editor where you're prompted to enter a commit message; but because you give the -m flag, that step is skipped.

I assume you're thinking that the diff is actually saved as part of the commit message, and that this is what makes the commit "verbose"? Generally it's not. If you fool git by removing all the comment lines that appear after where you're meant to type a message (but before the diff) then it will save the diff as the commit message.

I suppose you could do something like

git commit -m"$(git diff --staged)"

But the real question is: why do you want to do that? If you want to see a log of commits with their patches, use git log -p. Duplicating the diff in the commit message only serves to annoy people who want to see meaningful commit messages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...