创建基于ssh的git仓库

应用场景是部署一台远程机器,但是不希望每次部署都传一大堆代码,而可以在远程机器上直接编译。想到了用 Git 的 post-receive 方式部署,就要在远程建立一个 Git 仓库。 选用 ssh 方式比较好,可以很简单就建立起来;

1
2
3
mkdir example.git
cd example.git
git --bare init

然后在本地仓库就可以添加

1
2
3
git remote add upstream ssh://git@example.org/~/example.git
#推送
git push upstream master -f

当 git 遇到冲突而想使用远程仓库或者自己这边的代码时可以用以下方式解决冲突:

1
2
git checkout --ours {path_to_conflict_file}
git checkout --theirs {path_to_conflict_file}

以上命令只存在于 git 1.6.1 或者更高的版本中,在低版本中可以使用

1
2
3
4
5
6
7
# EQ git checkout --theirs {path_to_conflict_file}
git reset -- {path_to_conflict_file}
git checkout MERGE_HEAD -- {path_to_conflict_file}

#EQ git checkout --ours {path_to_conflict_file}
git reset -- {path_to_conflict_file}
git checkout ORIG_HEAD -- {path_to_conflict_file}