DEV Community

Discussion on: How to list commits from the current branch.

Collapse
 
ccoveille profile image
Christophe Colombier • Edited

alternatives

So here you are trying to provide an alias for something that exist in a very limited way:

git cherry

I don't know why no one use it, but I do.

It won't full achieve your need, but it provides almost the same.

you compute the current branch

you are using git branch --show-current because you want to add it to the master... thing

You could play with stack overflow to get the name of the branch from where the current branch come from.

You will find a lot of outdated thing using rev-parse, symbolic-ref or describe ... I'm not sure which one but it's around this.

But you simply doesn't need it, you can simply use master... that's it it works.

the three dots.

usually two are enough.

Then about the master

your code only works if your default branch is master (it doesn't work when it's main or devel ... )

It also doesn't work when you create a branch from another one, think about a bug fix in a feature branch.

here you can use @{upstream} alias, it works when your branch has an upstream.

it's not about a remote named upstream, but an internal thing.

Here is what I would use

git log --no-merges --oneline --decorate  @{upstream}..
Enter fullscreen mode Exit fullscreen mode

this won't work when you didn't set up an upstream to your branch.

There are way to find the first commit of your branch

conclusion

have fun, I will keep using git cherry -v no one knows

Collapse
 
sanixdarker profile image
darker

Interesting !
I didn't knew about git cherry
As i always say, there is an infinite way to solve a single problem !

I just learned, i can do the same with git cherry -v origin !

Awesome, thank you !

Collapse
 
ccoveille profile image
Christophe Colombier

about the 3 dots vs 2 dots thing

Some Git commands take commit ranges and one valid syntax is to separate two commit names with two dots .., and another syntax uses three dots ....

What are the differences between the two?