I’m encountering an odd behavior with git log when filtering by a specific directory. Here’s the command I’m using:
18:05:04 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git log --name-status --oneline --pretty=format:"COMMIT: %H" --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e -- 'force-app/main/default/'
COMMIT: ff565cdef935907ec6b8995463c907375a70f9f2
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
COMMIT: 84ee2707977848ff7a7b693b1e2f56f4b54c678d
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
However, when I run the command again, with the directory filter removed, I get a different list of modified files:
18:05:12 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git log --name-status --oneline --pretty=format:"COMMIT: %H" --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e
COMMIT: ff565cdef935907ec6b8995463c907375a70f9f2
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
COMMIT: 6e0d17558b091d00fe47304b588ec5e066c09d37
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParameters.cmp
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
M force-app/main/default/aura/GE_CL_SaveComponents/GE_CL_SaveComponents.cmp
M force-app/main/default/aura/GE_CL_SaveComponents/GE_CL_SaveComponentsController.js
M force-app/main/default/aura/GE_CL_SelectedComponent/GE_CL_SelectedComponent.cmp
M force-app/main/default/aura/GE_CL_SelectedComponent/GE_CL_SelectedComponentController.js
M force-app/main/default/classes/GE_CL_ComponentList_Controller.cls
M force-app/main/default/classes/GE_CL_ComponentList_Controller_Test.cls
M force-app/main/default/classes/RD3_ContractGenerator.cls
M force-app/main/default/classes/RD3_ContractGenerator_Test.cls
COMMIT: 84ee2707977848ff7a7b693b1e2f56f4b54c678d
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
As you can see, the list of resources changes even though all the resources have the same path. Why is git log
returning different results for the same directory filter across multiple executions?
The problem comes out with both zsh and bash.
I use git version 2.45.0.
Using gitk to show the state graphically:
gitk 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e
gitk 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e -- force-app/main/default/
I notice that by putting the filter on the directory, I hide the Commit on which I am positioned at checkout level, can anyone tell me how to avoid this result?
With the idea that more information can only help, I also show the result of the git diff in various forms, and as you can see, even here the result doesn't add up to me, it could be that the reason is that those files have not been modified compared to the current branch?
10:36:20 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git diff --name-status --oneline --pretty=format:"COMMIT: %H" --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
10:36:25 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git diff --name-status --oneline --pretty=format:"COMMIT: %H" --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e b0341db807cf7e4fa6b0dff63cf7eabca057308e
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
10:36:35 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git diff --name-status --oneline --pretty=format:"COMMIT: %H" --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e b0341db807cf7e4fa6b0dff63cf7eabca057308e -- 'force-app/main/default/'
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
I wanted to share a solution to an issue I encountered while using git log with a directory filter. Initially, when running the command:
15:28:46 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git log --name-status --oneline --pretty=format:"COMMIT: %H" --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e -- 'force-app/main/default/'
COMMIT: ff565cdef935907ec6b8995463c907375a70f9f2
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
COMMIT: 84ee2707977848ff7a7b693b1e2f56f4b54c678d
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
I received a list of modified files that did not match what I expected. Removing the directory filter changed the output, showing more modified files.
After some research and with the help of the community, especially @knittl, I discovered that the missing parameter was --full-history
. This parameter is crucial for including in the log all commits that have touched the specified path, even if the change was made on a branch that was later merged.
Here is the correct command that provides the expected output:
15:28:53 ~/Documents/01_repo/b2b-crm (uat)
└─▶ $ git log --name-status --oneline --pretty=format:"COMMIT: %H" --full-history --diff-filter=ACDMRTUXB 814cfc685b430020192e7c0db04b2874b5790a1e..b0341db807cf7e4fa6b0dff63cf7eabca057308e -- 'force-app/main/default/'
COMMIT: ff565cdef935907ec6b8995463c907375a70f9f2
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
COMMIT: 6e0d17558b091d00fe47304b588ec5e066c09d37
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParameters.cmp
M force-app/main/default/aura/GE_CL_ConfigurationParameters/GE_CL_ConfigurationParametersController.js
M force-app/main/default/aura/GE_CL_SaveComponents/GE_CL_SaveComponents.cmp
M force-app/main/default/aura/GE_CL_SaveComponents/GE_CL_SaveComponentsController.js
M force-app/main/default/aura/GE_CL_SelectedComponent/GE_CL_SelectedComponent.cmp
M force-app/main/default/aura/GE_CL_SelectedComponent/GE_CL_SelectedComponentController.js
M force-app/main/default/classes/GE_CL_ComponentList_Controller.cls
M force-app/main/default/classes/GE_CL_ComponentList_Controller_Test.cls
M force-app/main/default/classes/RD3_ContractGenerator.cls
M force-app/main/default/classes/RD3_ContractGenerator_Test.cls
COMMIT: 84ee2707977848ff7a7b693b1e2f56f4b54c678d
M force-app/main/default/aura/IS_ImprimirContrato_Quadient/IS_ImprimirContrato_QuadientHelper.js
With this command, git log now shows all the files modified in the specified path, regardless of the branch where the changes were made.
I hope this solution can be helpful to others who find themselves in the same situation.