I have a feature branch concisely named feature
that has about 100 commits all related to a feature of sorts. These commits were all merged into the master branch over the time. I want to list all commits that were on the branch so I can re-add the feature to other project.
Basically I want to have commit IDs for the green dots on the graph below.
How can I do that in Git other then by going to gitk or similar tool and hand-collecting all the relevant commit IDs?
Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.
On GitHub, you can see the commit history of a repository by: Navigating directly to the commits page of a repository. Clicking on a file, then clicking History, to get to the commit history for a specific file.
2.1 git log to display all the commit_id, the first one is the last commit_id, copy it. 2.2 git show commit_id --name-only to display all the files committed in the specified commit_id.
Git rebase interactive in the console To use git rebase in the console with a list of commits you can choose, edit or drop in the rebase: Enter git rebase -i HEAD~5 with the last number being any number of commits from the most recent backwards you want to review. In vim, press esc , then i to start editing the test.
If you get the starting point of the specific branch, e.g., SHA1
, try this:
git log --pretty=oneline SHA1^..feature
Despite answer is given and accepted I would suggest more automatic way for doing this (but it will only work if you did not merge your master
to feature
):
Considering the following history:
--A---B---C---D---E---F---G (master)
\ / /
H---J-------K (feature)
Basically we want to perform git log B..feature
.
git log --format='%H' feature..master | tail -1 | \
xargs -I '{}' git log '{}'^..feature
git log --format='%H' feature..master | tail -1
will find the commit to the master
that was done right after you created feature
branch - this is C
And ancestor of C
- B
will also be the ancestor of the first commit H
of feature
branch.
Then xargs -I '{}' git log '{}'^..feature
(that is turns to git log B..feature
) just shows the commits that is reachable from feature
but don't reachable from the B
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With