Home >Git: How to Export Changes (in File) Between 2 Commits

Git: How to Export Changes (in File) Between 2 Commits

For code review purpose, sometimes exporting all changes between 2 commits is an effective way. This is how it works:

– Check commit history again on branch (suppose that we need to see on development branch)

git log –oneline development

Output:

98b47a6 HER-64: Flipping book button

b90eecc HER-65 – fixed problem with js, css and layout

b367828 HER-62: fix hidden mobile menu item

8b0f589 HER-57: Package Price show/hide for customergroup

64cb36d Merge branch ‘development’

 

– For example, we need to see changes between 64cb36d and 98b47a6, we use command:

git diff 64cb36d^..98b47a6

– If you need to export to file: git diff 64cb36d^..98b47a6 > somefile.txt

 

There are several other ways of diff command:

– Compare present code with the code in staging area: git diff

– Compare present code with the last commit: git diff –staged

– Compare present code with commit b5c0c61: git diff b5c0c61

– Compare code between commit b5c0c61 and the last commit: git diff b5c0c61 HEAD

– Compare code between commit 64cb36d and 98b47a6: git diff 64cb36d 98b47a6

 

Referrence: https://git-scm.com/docs/git-diff

< Previous Post
Next Post >
+ posts