dCoder
dCoder

Reputation: 549

Search git reflog

I create a new branch when a new issue pops up. These branches are named starting issu. After merging with master these branches are deleted. I wanted to get a list of all such branches. I was able to get it using git reflog

>git reflog
55e8b45 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: merge issu4-HasScript-and-HasFormat-checkbox-toggle: Fast-forward
7caf2c6 HEAD@{1}: checkout: moving from issu4-HasScript-and-HasFormat-checkbox-toggle to master
55e8b45 (HEAD -> master, origin/master, origin/HEAD) HEAD@{2}: commit (amend): Column validation including Has-Script and Has-Format
490a29a HEAD@{3}: commit: Column validatio inclnsuding Has Script and Has Format
7caf2c6 HEAD@{4}: checkout: moving from master to issu4-HasScript-and-HasFormat-checkbox-toggle
7caf2c6 HEAD@{5}: merge issu3-make-SFTPFingerprint-required: Fast-forward
fbad7cd HEAD@{6}: checkout: moving from issu3-make-SFTPFingerprint-required to master
...

Is there any way to filter these entries to get all merges starting with issu.

I am trying to get all deleted branches that were merged into the master and started with issu. Other solutions that get these are also fine.

I searched a lot and could not find a solution.

Update:

I am using windows. The solution that i currently have is

git reflog | findstr /c:"merge issu"

Is there any solution in git itself?

Upvotes: 10

Views: 9382

Answers (3)

VonC
VonC

Reputation: 1323753

With Git 2.45 (Q2 2024), batch 3, "git reflog"(man) learned a list subcommand that enumerates known reflogs.

That could help in your case, to list all branches with reflog entries.

See commit f7cdeaf (19 Feb 2024) by Junio C Hamano (gitster).
See commit d699d15, commit 59c50a9, commit 31f8983, commit 5e01d83, commit 6f22780, commit e69e8ff, commit de34f26, commit 0218de2 (21 Feb 2024) by Patrick Steinhardt (pks-t).
(Merged by Junio C Hamano -- gitster -- in commit 510a27e, 01 Mar 2024)

builtin/reflog: introduce subcommand to list reflogs

Signed-off-by: Patrick Steinhardt

While the git-reflog(1) command has subcommands to show reflog entries or check for reflog existence, it does not have any subcommands that would allow the user to enumerate all existing reflogs.
This makes it quite hard to discover which reflogs a repository has.
While this can be worked around with the "files" backend by enumerating files in the ".git/logs" directory, users of the "reftable" backend don't enjoy such a luxury.

Introduce a new subcommand git reflog(man) list that lists all reflogs the repository knows of to fill this gap.

git reflog now includes in its man page:

'git reflog list'

git reflog now includes in its man page:

The "list" subcommand lists all refs which have a corresponding reflog.

Upvotes: 1

Saurabh P Bhandari
Saurabh P Bhandari

Reputation: 6742

You can use this command,

git reflog --grep-reflog=<pattern>

In your case it would be, git reflog --grep-reflog="merge issu"

Link

Upvotes: 25

Code-Apprentice
Code-Apprentice

Reputation: 83527

If you are on Linux, grep is the tool for this job, along with pipes which allow you to take the output from one command as the input for another command. In this case, you can do

git reflog | grep issu

For more info, type man grep for the grep documentation.

Note: In all Windows flavors, you can use Git Bash to do this. In Windows 10, you can use the Linux subsystem.

Upvotes: 0

Related Questions