I'll just explain my scenario.
I have a folder managed with git containing a set of scripts which are automatically run. Each script have a corresponding filter file determining wh开发者_StackOverflowich files are to be run in response to different events. E.g.:
- a.script
- a.filter
- b.script
- b.filter
I have a branch containing some changes to the scripts, but we've decided for the time being to only roll them out for certain scenarios using the filters. So we'll end up with something like:
- a.script
- a_.script
- a.filter
- a_.filter
- b.script
- b_.script
- b.filter
- b_.filter
So what I need is to have the script files from the main branch, and the script files from the testing branch checked out together in one folder, with different names. I don't know when (or if) the testing branch will be merged into main, so I need to push changes to both branches. Is there any good way to solve this using git?
You already seem to have your additional or modified files in a separate branch (I’ll assume its name is testing
); this branch should also contain the files from the master
branch (because it was created from master
, right?). Now create a third branch, e.g. local
(or unified
or whatever):
git checkout -b local master
Now merge your testing
branch into it:
git merge testing
This should basically give you all modifications from all branches. Note that this branch is not for committing manually, you only merge either your master
or your testing
branch into it, commits always go to either of those branches, never to local
!
This approach requires a bit of discipline because you should not commit to the local
branch (unless you’re confident that you can rebase
the commits to the local
branch to the branch they should really go to). Also, it will look quite messed up in gitk
because continued merges into a single branch tend to create some optical noise. This can be cleared up every now and then by repeating the two steps from above that will simply recreate the local
branch — this is not a problem because all your changes have been committed to either master
or testing
.
精彩评论