How to list only file names that have changed between two branches
This command will diff their whole history:
git diff branch1..branch2 --name-only
If you want to compare from their last common ancestor, then:
git diff branch1...branch2 --name-only
And now you can grep files that you want. From there it's easy to write a little shell script that diffs two branches, file by file.
filenames=$(git diff branch1...branch2 --name-only | grep /db/migratons) IFS=' ' read -r -a filearr <<< "$filenames" for filename in "${filearr[@]}" do echo $(git diff branch1...branch2 -- "$filename") done
Create the git-command-name
file and put it into the user/bin
folder (you should parametrize input - branches as variables).
Git will recognise it as a command that you can call with:
git command-name branch1 branch2
Related videos on Youtube
Deepak Mahakale
Deepak Mahakale is a Ruby on Rails Developer with 7 years of experience. He is currently working as a Senior Software Developer at Saeloun. Deepak has previously worked with Velotio Technologies and Webonise Lab. Deepak also knows about JavaScript, Bootstrap, HTML, HAML, Git, GitHub, Heroku, Spree Commerce, PostgreSQL, MySQL and Linux. Deepak is continuously contributing to open source communities. He is an active user on Stack Overflow with a reputation of more than 18k. He has also contributed to Spree which is one of the most popularly used e-commerce platforms.
Updated on June 04, 2022Comments
-
Deepak Mahakale almost 2 years
I have two branches in my repository which I want to diff for some files.
I want to list only newly added migrations between those two branches.
Something like:
git diff branch1 branch2 | grep /db/migrate
How can I do it?
-
neuhaus over 7 yearsWhat do you mean by "newly added migrations"?
-
Tim Biegeleisen over 7 yearsPossible duplicate of Showing which files have changed between two revisions
-
Deepak Mahakale over 7 yearsnewly added migrations between two branches one old and one new
-
-
dotnetCarpenter over 2 yearsNice! I was looking for the
--name-only
option.