I'm pretty new to git, so forgive me if this is obvious (or impossible)!
I am using it for CMS websites. I often run into the situation where I have made modifications to a 3rd-party component that is then updated.
How can I add the changes from the updated component as if they had happened before my changes? or is this 'rewriting history'?
Do I create a branch from an old commit where the component was introduced, add the updated code and then merge into master? submodules? or am I barking up the wrong tree and this situation is better handled another way?
Is the 3rd party component an open source one with a public repo? In that case, you'd be best off forking the repository, and adding a branch with your modifications in. This branch can be 'rebased' when updates from the 3rd party component come in, to sit 'on top' of the latest commits on the master branch.
ReplyDeleteSo, on the command line, assuming we're starting from the beginning:
git clone thirdparty.org/shinything.git
git checkout -b tweaks // creates your new branch
... make your tweaks, commit them
Later, when you the third party has created some updates...
git checkout master
git pull origin master // get the latest updates from the 3rd party
git rebase master tweaks // re-bases the commits from your tweaks branch
This will leave your tweaks as effectively being the last thing that happened.
The approach is actually pretty much the same if you don't have access to the 3rd party components repo - you basically just have to start your own repo, and put the changes you receive into the master branch yourself, rather than doing a pull.