简体   繁体   中英

Keeping local changes in git while pulling from remote

Say I am working on a shared repo. In that repo is a defaults.js file that specifies various URLs. When I clone the repo locally, I change some of these URLs to point at services that are running locally. How can I keep these URLs set to the local values, while pulling new updates from remote?

So far I have been happily (naively?) using the method described here

git stash
git pull
git stash pop

but while trying this today I received a

CONFLICT (content): Merge conflict in config/defaults.js

Since we rebase rather than merge, I didn't want to start creating messy merges, particularly for something so trivial. So I just reset, got rid of my changes so local mirrored remote, and then manually changed the URLs again. Obviously, I don't want to keep doing this, what is the preferred approach?

The solution in the link above says to simply

git checkout --theirs -- defaults.js

because you know that what you put in the stash is what you want. But that's not true in my case, I do want a merge of mine and theirs, without actually merging.

As long as you're maintaining a different state than origin that you don't want committed, you're going to run into conflicts like this, and the things you're already trying are pretty much the simplest ways to fix it.

There are a couple cleaner ways to solves this for good that avoid futzing with Git:

  1. If you can use environment variables, set up defaults.js to prefer those and fall back to another default contained in the file. Then you can set your local ENV differently than your coworkers or production.

  2. Set up a local-defaults.js file that's preferred over defaults.js (either wholesale or by merging options), and add it to .gitignore so it's not committed. Then everyone can keep their own file with whichever overrides they need.

Both of these are a code change - effectively a new feature - but as your team size grows everyone will be happy they have proper customization available without having to fight through the stash dance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM