Cargo Build on Different Envs

Hello. I have next problem with Cargo.toml files.
I use a lot of my private repositories in projects and fetch these repos by using cargo + git.
For example:
my-dep = { git = ", branch = "develop" }
And it works perfectly. However, I have a problem when I want to have different branches for different environments: dev, test, and stage. So it means that on different branches my Cargo.toml should have a different { branch = } field. Can someone help to find the solutions? If I just put the branch name git will overwrite it in the next merge from dev to test.

What exactly do you mean with environments? Do you mean profiles?

backend environments = dev - for developers, test - for QA, etc

Yeah, but how do you specify your environments? What does your build process look like when you build for dev compared to test?

Ah, ok, sorry. Just cargo build but in toml file I have next
Cargo.toml on dev branch
my-dep = { git = "url", branch = "dev" }

Cargo.toml on test branch
my-dep = {git = "url" branch = "test" }

In case I want to merge develop to test git will overrite Cargo.toml

Ah, okay, yes, that makes sense to me.

But isn't that just a problem with git during merging? You can specify to keep certain files from being merged by specifying git config --global merge.ours.driver true once and then add this line to a .gitattributes file:

Cargo.toml merge=ours

that should keep the Cargo.toml from the original branch instead of applying the changed from the branch you merge. Taken from this medium article.