开发者

Git Merge Old Modified Version and New Unmodified

开发者 https://www.devze.com 2023-02-08 09:21 出处:网络
I\'m working on improving one popular php forum software. A month ago I\'ve initiated a repository with git for version 1.0:

I'm working on improving one popular php forum software. A month ago I've initiated a repository with git for version 1.0:

git init .
(copied files here of version 1.0)
git add .
git commit

after that I was working on improving the this software for 1 month (making commits). Now new official version is available. The version is 1.1. I have to merge new features of the forum without removing my code.开发者_开发知识库 What git commands should I use?

I try to make the following:

1) git branch vendor
2) git checkout vendor
3) delete old files and put files of version 1.1
4) git checkout master
5) git merge vendor

But when I did that, I lost all my modifications. Where I go wrong? Thank you.


Ideally, the software you're working on should already have a publicly accessible repository of some sort, which you should be able to slurp in with git-svn or some other importer. Assuming that's for some reason not possible, here's what I'd recommend.

Create a branch called "vendor", but starting from the commit where you added version 1.0 (looks like it's your root commit). Whenever a new version appears, check out that branch, delete everything, and dump in the release (just as you say). The important part: never include any of your changes on this branch. You can then freely merge it into your master branch. You may experience merge conflicts more frequently with this workflow, since a new release may make a large number of modifications. Hazard of the job.

Your history should ultimately look like this:

x [1.0] ------- x [1.1] ------------ x [1.2] (vendor)
 \               \                    \
  o - o - o - o - o  - o - o - o - o - o (master)

The bold text, by the way, is where you went wrong. You started the vendor branch from your master branch, so when you committed v1.1, your history looked like this:

x [1.0] - o - o - o - o - o (master) - x [1.1] (vendor)

So naturally, when you merged vendor into master, you ended up with precisely v1.1.

0

精彩评论

暂无评论...
验证码 换一张
取 消