接我的上一篇博文。
一.修改同一文件,同一内容时的处理。
(1)先在test2中的Readme中。添加一行声明。然后提交push.
banxi1988@banxi :~/work/git_repo/test1.git$ cat Readme.txt init a Readme add a line banxi1988@banxi :~/work/git_repo/test1.git$ vi Readme.txt banxi1988@banxi :~/work/git_repo/test1.git$ git commit -a -m"add call" [master b9595c4] add call 1 file changed, 1 insertion(+) banxi1988@banxi :~/work/git_repo/test1.git$ git push Counting objects: 5, done. Writing objects: 100% (3/3), 273 bytes, done. Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. To /home/banxi1988/work/git_repo/test.git/ 176fe01..b9595c4 master -> master banxi1988@banxi :~/work/git_repo/test1.git$ cat Readme.txt init a Readme add a line We are family banxi1988@banxi :~/work/git_repo/test1.git$
然后在test2.中的仓库中也对Readme.txt进行修改并提交。先不push.
banxi1988@banxi :~/work/git_repo/test1.git$ cd ../test2.git/ banxi1988@banxi :~/work/git_repo/test2.git$ cat Readme.txt init a Readme add a line banxi1988@banxi :~/work/git_repo/test2.git$ vi Readme.txt banxi1988@banxi :~/work/git_repo/test2.git$ cat Readme.txt init a Readme add a line You are my girlfirend! banxi1988@banxi :~/work/git_repo/test2.git$ git commit -a -m"add a intro" [master 17d2783] add a intro 1 file changed, 1 insertion(+) banxi1988@banxi :~/work/git_repo/test2.git$
下面我们来看看,如果push的话会有什么问题。
根据使用svn的 经验。如果是svn的话,他会提示说out of date之类的话,
让我们先更新,然后再提交。那么git会怎么做呢?
果然git提醒如下:
banxi1988@banxi :~/work/git_repo/test2.git$ git push To /home/banxi1988/work/git_repo/test.git/ ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '/home/banxi1988/work/git_repo/test.git/' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. banxi1988@banxi :~/work/git_repo/test2.git$那我们照着提示,先执行git pull然后看会发生什么。如下:
banxi1988@banxi :~/work/git_repo/test2.git$ git pull remote: Counting objects: 5, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From /home/banxi1988/work/git_repo/test 176fe01..b9595c4 master -> origin/master Auto-merging Readme.txt CONFLICT (content): Merge conflict in Readme.txt Automatic merge failed; fix conflicts and then commit the result. banxi1988@banxi :~/work/git_repo/test2.git$从上面输出的信息我们可以看出,
它将远程仓库中的更新获取回来了。但是在尝试自动合并时发生了冲突。
它同时提示我们在解决冲突之后提交结果。
同svn一样,它会将内容同时加入到文件中中,并以标记出那些内容是冲突的。
banxi1988@banxi :~/work/git_repo/test2.git$ cat Readme.txt init a Readme add a line <<<<<<< HEAD You are my girlfirend! ======= We are family >>>>>>> b9595c404d119a4e0092dd7c7092d1aa60b44811 banxi1988@banxi :~/work/git_repo/test2.git$
然后我们手动合并提交,push,OK。
banxi1988@banxi :~/work/git_repo/test2.git$ vi Readme.txt banxi1988@banxi :~/work/git_repo/test2.git$ cat Readme.txt init a Readme add a line You are my girlfirend! We are family banxi1988@banxi :~/work/git_repo/test2.git$ git commit -a -m"merge two call" [master d1a31da] merge two call banxi1988@banxi :~/work/git_repo/test2.git$ git push Counting objects: 10, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (6/6), 574 bytes, done. Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done. To /home/banxi1988/work/git_repo/test.git/ b9595c4..d1a31da master -> master banxi1988@banxi :~/work/git_repo/test2.git$
然后,我们再到tes1仓库中pull看看。
banxi1988@banxi :~/work/git_repo/test1.git$ cat Readme.txt init a Readme add a line We are family banxi1988@banxi :~/work/git_repo/test1.git$ git pull remote: Counting objects: 10, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done. From /home/banxi1988/work/git_repo/test b9595c4..d1a31da master -> origin/master Updating b9595c4..d1a31da Fast-forward Readme.txt | 1 + 1 file changed, 1 insertion(+) banxi1988@banxi :~/work/git_repo/test1.git$ cat Readme.txt init a Readme add a line You are my girlfirend! We are family banxi1988@banxi :~/work/git_repo/test1.git$
有时候git push并不能使用,是因为什么呢?
得使用git push orign master
banxi1988@banxi :~/work/uplus/base$ git push No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. fatal: The remote end hung up unexpectedly error: failed to push some refs to '/home/banxi1988/work/uplus/../git_repo/uplus.git' banxi1988@banxi :~/work/uplus/base$ git push origin master Counting objects: 555, done. Delta compression using up to 4 threads. Compressing objects: 100% (535/535), done. Writing objects: 100% (555/555), 7.45 MiB | 11.16 MiB/s, done. Total 555 (delta 137), reused 0 (delta 0) To /home/banxi1988/work/uplus/../git_repo/uplus.git * [new branch] master -> master banxi1988@banxi :~/work/uplus/base$
二,标签,打标签
1.git tag,会列出所有标签。
使用-a参数来打带附注的标签。
使用git show <tagname>
来查看具体的某一个标签
banxi1988@banxi :~/work/uplus/base$ git tag banxi1988@banxi :~/work/uplus/base$ git tag -a v0.1 -m"v0.1 only support gxu gxufe" banxi1988@banxi :~/work/uplus/base$ git tag v0.1 banxi1988@banxi :~/work/uplus/base$ git show v0.1 tag v0.1 Tagger: banxi1988 <[email protected]> Date: Wed Sep 12 18:01:36 2012 +0800 v0.1 only support gxu gxufe commit 8ef2e1924e924fd337fe47109cc4f6cfd8955aca Author: banxi1988 <[email protected]> Date: Wed Sep 12 17:54:59 2012 +0800 init the import the uplus android project diff --git a/AndroidManifest.xml b/AndroidManifest.xml
2.将某一个标签分享的远程仓库中:
banxi1988@banxi :~/work/uplus/base$ git push origin v0.1 Counting objects: 1, done. Writing objects: 100% (1/1), 166 bytes, done. Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. To /home/banxi1988/work/uplus/../git_repo/uplus.git * [new tag] v0.1 -> v0.1 banxi1988@banxi :~/work/uplus/base$