How do I incorporate a new source code updates while keeping my existing modifications in Git?

StackOverflow https://stackoverflow.com/questions/22559804

  •  18-06-2023
  •  | 
  •  

문제

So far, I've been using Git and it's tolerable for simple pushes and merges, but I just got a curve ball thrown at me. The developers of the source code I am using just released a new version release as a source tree. Several files have been changed and I am having difficulty figuring out how to incorporate the new source such that I can keep the old version of their code with my modifications as one branch, say Version 1.0, and the new version of their code with the same modifications as another branch, say Version 2.0. I'm the only one working on the project, so I don't care about rewriting the history if I have too. Ideally, I would like to be able to continue making my modifications and have them apply to both versions.

도움이 되었습니까?

해결책

You can use submodule for code of library you are using , so will be able to have 2 brunches in this submodule (Version 1.0 and Version 2.0) and use master branch for your code. In such case when your changes will be done you will be able to easily provide them with both Version 1.0 and Version 2.0 just by switching branch in submodule

code example

cd /path/to/project/
mv lib /some/other/location/
git rm lib
git commit -m'move lib to submodule'
cd /some/other/location/lib
git init
git add .
git commit
cd /path/to/project/
git submodule add /some/other/location/lib
git commit -m'add submodule'
cd /some/other/location/lib
git checkout -b version2
do some modifications
git commit -m'version2'
cd /path/to/project/lib
git fetch --all

now you can simply switch between version1 and version2 by

cd /path/to/project/lib
git checkout version2
git checkout master

another variant using rebase (not recommended). lets say you have muster branch with version1 of you lib

git checkout -b version2
apply changes in you lib wich will bring it to version 2.
git commit
git checkout master

now do your work in master (commit something). To see your master changes in version2 branch do

git checkout version2
git rebase master 

다른 팁

Based on your comments, I think you have to take a similar approach no matter what source code control system you choose.

Keep the vendor code in one repository and your own code in its own repository.

If you have to patch or change the vendor code, then maintain the change management in the vendor repository. If you get a new vendor drop, then, use branches and tags to manage it in the vendor repo.

If you think you have difficulty because your directory tree is intermingled with vendor code and your own code, you need to find a way to separate the two. That is true no matter what source code management system you use. One way is to use symlinks to link vendor code in another directory into a directory in your own repo and do a .gitignore for that vendor symlink in your repo. To switch vendor versions, you go to the vendor directory and do a git checkout of the desired version.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top