Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: want to iterate through all commits on branch, and list files in each commit

Tags:

I need to write a script that will

  1. iterate through all of the commits on a branch, starting from the most recent
  2. for each commit, iterate through all of the files in the commit
  3. if it finds a file of type hbm.xml, store the commit to file and exit.

I have a script for step 2:

for i in `git show --pretty="format:" --name-only SHA1 | grep '.*\.hbm\.xml' `; do     # call script here.....     exit done 

Now, I need to figure out step 1.

like image 649
Jacko Avatar asked May 10 '11 17:05

Jacko


People also ask

How do I get a list of all commits?

On GitHub.com, you can access your project history by selecting the commit button from the code tab on your project. 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.

Which command displays the list of all commits?

The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA)

How do you see the details of a commit?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.

Is it good to have many commits?

More commits is great. As long as they get finer-grained and have good messages, they're useful.


1 Answers

Something like:

for commit in $(git rev-list $branch) do     if git ls-tree --name-only -r $commit | grep -q '\.hbm\.xml$'; then         echo $commit         exit 0     fi done 

Note that git show will only list files which have changed in that commit, if you want to know whether there is a path that matches a particular pattern in a commit you need to use something like git ls-tree.

like image 63
CB Bailey Avatar answered Sep 21 '22 13:09

CB Bailey