这里有一个使用git和分支的示例。
$ git branch
* master
organize
$ git branch networking
$ git checkout networking
$ git branch
master
* networking
organize
自从有人停止网络开发以来,Master已经多次更新。
$ git pull origin networking
From github.com:dlundquist/Asteroids
* branch networking -> FETCH_HEAD
CONFLICT (rename/delete): Rename src/ServerClientThread.java->src/ServerConnectionThread.java in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 and deleted in HEAD
Auto-merging src/Actor.java
Auto-merging src/Asteroids.java
CONFLICT (content): Merge conflict in src/Asteroids.java
Auto-merging src/BasicWeapon.java
CONFLICT (content): Merge conflict in src/BasicWeapon.java
CONFLICT (delete/modify): src/DedicatedServer.java deleted in HEAD and modified in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722. Version 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 of src/DedicatedServer.java left in tree.
Auto-merging src/MainMenu.java
CONFLICT (content): Merge conflict in src/MainMenu.java
CONFLICT (delete/modify): src/NetworkClientThread.java deleted in HEAD and modified in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722. Version 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 of src/NetworkClientThread.java left in tree.
CONFLICT (delete/modify): src/NetworkUpdate.java deleted in HEAD and modified in 92d5b7c4e7c4110803eabf5d5152e7f2a337d722. Version 92d5b7c4e7c4110803eabf5d5152e7f2a337d722 of src/NetworkUpdate.java left in tree.
Auto-merging src/ScenePanel.java
CONFLICT (content): Merge conflict in src/ScenePanel.java
Auto-merging src/Shield.java
CONFLICT (content): Merge conflict in src/Shield.java
Auto-merging src/Sprite.java
Auto-merging src/TripleShotWeapon.java
Auto-merging src/Weapon.java
Automatic merge failed
mjolnir:Asteroids Durandal$ git status
哇,git真的很生气。看起来Master版本已经超前于Networking分支了,所以git不能为我完成所有的工作。
$ git reset --hard networking
HEAD is now at 20d6ee8 done tweaking game on the main branch. Fixed a few bugs with the TripleShotWeapon. Rebalanced the gameMechanics() in Asteroids to increase the difficulty as the levels increase.
mjolnir:Asteroids Durandal$ git status
# On branch networking
nothing to commit (working directory clean)
现在,我回到了上次将网络推到远程时的状态。但在进行任何工作之前,我真的应该回去并与主分支合并。否则,合并会更加困难。
合并文件所花费的时间
$ git add (insert conflict resolved files here)
$ git commit -a -m "Merged networking with master"
$ git checkout master
$ git branch
* master
networking
organize
现在让我们应用我们所做的更改。
$ git merge networking
Already up-to-date.
如果你喜欢“Yeah!”的话,你可能想这样做。
$ git merge origin networking
Already up-to-date. Yeeah!
将我们的更改推送到世界上
$ git push origin master