Skip to content

git.log() command doesn't log commits from merges #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thomastangerine opened this issue Feb 8, 2023 · 3 comments
Closed

git.log() command doesn't log commits from merges #896

thomastangerine opened this issue Feb 8, 2023 · 3 comments
Labels
more-info-needed More information is required in order to investigate

Comments

@thomastangerine
Copy link

I am using the simple-git's git.log() call to retrieve the latest commit on a particular directory.

My code is as follows:

const gitOptions: LogOptions<DefaultLogFields> = { file: docfxPath }

const git: SimpleGit = simpleGit(docfxPath, { binary: 'git' });

const log = await git.log(gitOptions);

console.log(log.all.slice(0, 5));
const latestCommitId = (await git.log(gitOptions)).latest?.hash;

When I run the git log terminal command on that same directory, I get the list as follows:

MicrosoftTeams-image (8)

However, the list of commits returned by the simple-git call in my code above returns the following list of commits, with the latest commit with message "Merge branch 'thomastang/pushmodel' ... " not being present:
MicrosoftTeams-image (9)

The git.log().latest field also improperly has the value of the second to latest commit, with the message "empty commit".

My guess is that Simple-Git's git.log() call for some reason does not include commits that are from merges. I was wondering if my assumption is correct, and if there is a way to retrieve commit logs including commits from merges using Simple-Git?

@steveukx
Copy link
Owner

steveukx commented Apr 8, 2023

Hi, apologies for the super delayed response.

There's no obvious reason for merge commits not showing up - so if you didn't find a cause for this please can you run the script with verbose logging enabled.

The verbose logs show the command that simple-git passed into git, along with all the data that was received. Does manually running the command simple-git generates also miss the merge commit?

@steveukx steveukx added the more-info-needed More information is required in order to investigate label Apr 8, 2023
@github-actions
Copy link
Contributor

This issue has been automatically closed due to a lack of response. If your problem persists please open a new issue including any additional detail requested from this issue. For more detail on the issues/pull requests see ISSUES_AND_PULL_REQUESTS

@jankrynauw
Copy link

This seems to be related to the --first-parent argument.

When you use --first-parent, git log follows only the first parent of a merge commit. This effectively gives you a "linear" view of the branch's history, showing only the commits that were directly made onto that branch, and skipping the detailed history of merged feature branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-info-needed More information is required in order to investigate
Projects
None yet
Development

No branches or pull requests

3 participants