简体   繁体   中英

git log pretty format for a certain branch

I am trying to use the git log pretty format command to input the log into a json file. Currently I am using this command to get the specific git attributes:

git log --pretty="format:{commit:%h,%n merge:%p,%n author:%an,%n title:%s,%n body:%b,%n}">git_log.json

The problem with this command is that it gets the logs of all the branches in the system and inputs into the json. I only want to use this command to input logs of a certain branch that I can input somehow.

I tried checking out the certain branch that I want to get the log off and then used that command but it did not work as it still showed logs of all the existing branches. This was my failed attemmpt in the cmd line:

git checkout robotics/ashish_c/infrastructure
git fetch

git log --pretty="format:{commit:%h,%n merge:%p,%n author:%an,%n title:%s,%n body:%b,%n}">git_log.json

But it gave me the log files of other branches as well. How do I only get the pretty format log file of only the branch robotics/ashish_c/infrastructure?

The problem with this command is that it gets the logs of all the branches in the system and inputs into the json.

That should not be so. git log gets the log of the currently checked out commit and its history. git log --all gets the logs of all branches.

Git history is not linear and it may look like you're getting the history of other branches which have been merged into the current commit. git log --graph --decorate will show you the true history.

How do I only get the pretty format log file of only the branch robotics/ashish_c/infrastructure?

git log robotics/ashish_c/infrastructure

I am trying to use the git log pretty format command to input the log into a json file.

JSON keys and strings must be quoted. I've removed the newlines to simplify things, this isn't for human consumption. Instead try...

git log --format='{"commit":"%h", "merge": "%p", "author": "%an", "title": "%s", "body":"%b"},' > git_log.json

But that leaves you with no wrapping [] and a trailing , .

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