Php get Commit list of specfic Git Branch

791

I want to get commits of specific branch. following is my code

exec("git log $branch", $logs);

$branch may be master or any other branch. But this give all commits.

961

Answer

Solution:

But this give all commits.

Sure: it gives all commits reachable frommaster HEAD, which are all commit even if they are part of another branch. Up to the very first one (usually done on the master branch)

Even if you were to use another branch, you would still get all commit reachable from that other branch HEAD, even if they are part ofmaster (assuming that other branch was done from one of master commits)

x--x--x--X           (master)
          \
           --o--o--O (anotherBranch)

git log anotherBranch = O-o-o-X-x-x-x

That is why you need two parameters: one which will start the commit retrieval, one which will stop it:

git checkout mybranch
git log --all --not $(git rev-list --no-walk \
    --exclude=refs/heads/mybranch \
    --exclude=HEAD \
    --all)

Put that in your Php command, and you will get only the commits you are after.

People are also looking for solutions to the problem: Php Imagine get Image's width and height

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.