First of all I am aware of the accepted answer for the following question:
Should .terraform.lock.hcl be included in the .gitignore file?
That's why I version the lock file. But (maybe because I don't fully understand the answer) I fail to infer from it how to deal with the lock file across branches representing different stages / environments.
Let me explain.
The project repo has three branches: dev, test, prod
Those branches correspond to three different GCP projects representing respective environments. Branch dev is deployed to project dev etc. The deployment workflow then is to merge branches from dev to test to prod.
But if the lock file represents the terraform state then wouldn't merging a lock file from dev to test and from test to prod be introducing a mismatch or conflict of actual state of the environment and the state encoded in the lock file? Because the branch of test then holds the state of dev and so on.