大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

Git教程
Git標(biāo)簽管理
Git分支
Git操作
Git應(yīng)用
GitHub應(yīng)用
IDEA對于Git&GitHub的支持
Git與GitHub使用注意事項

Git更新操作

在本文章教程中,我們將演示如何查看 Git 存儲庫的文件和提交文件記錄,并對存儲庫中的文件作修改和提交。

注意:在開始學(xué)習(xí)本教程之前,先克隆一個存儲庫,有關(guān)如何克隆存儲庫,請參考:Git克隆操作

執(zhí)行克隆操作,并得到了一個新的文件:main.py。想知道誰將這個文件修改變提交到存儲庫中,那么可以執(zhí)行g(shù)it log命令,為了更好的演示,開發(fā)人員minsu另外一臺機(Ubuntu Linux)上,使用以下命令克隆:

bjpowernode@ubuntu:~$ cd /home/bjpowernode/git
bjpowernode@ubuntu:~/git$ git clone http://git.oschina.net/bjpowernode/sample.git
Cloning into 'sample'...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
Checking connectivity... done.
bjpowernode@ubuntu:~/git$

克隆操作將在當(dāng)前工作目錄中創(chuàng)建一個新的目錄(sample)。 將目錄更改(cd /home/bjpowernode/git/sample)為新創(chuàng)建的目錄,并執(zhí)行g(shù)it log命令。

bjpowernode@ubuntu:~/git$ cd /home/bjpowernode/git/sample
bjpowernode@ubuntu:~/git/sample$ git log
commit 51de0f02eb48ed6b84a732512f230028d866b1ea
Author: your_name 
Date:   Fri Jul 7 23:04:16 2017 +0800

    add the sum of a & b

commit be24e214620fa072efa877e1967571731c465884
Author: your_name 
Date:   Fri Jul 7 18:58:16 2017 +0800

    ??????mark

commit 5eccf92e28eae94ec5fce7c687f6f92bf32a6a8d
Author: your_name 
Date:   Fri Jul 7 18:52:06 2017 +0800

    this is main.py file commit mark use -m option

commit 6e5f31067466795c522b01692871f202c26ff948
Author: your_name 
Date:   Fri Jul 7 18:42:43 2017 +0800

    this is main.py file commit mark without use "-m" option

commit 290342c270bc90f861ccc3d83afa920169e3b07e
Author: Maxsu <769728683@qq.com>
Date:   Fri Jul 7 16:55:12 2017 +0800

    Initial commit
bjpowernode@ubuntu:~/git/sample$

觀察日志后,可以看到maxsu添加了文件代碼來實現(xiàn)兩個變量a和b之和,現(xiàn)在假設(shè)minsu在文本編輯器中打開main.py,并修改優(yōu)化代碼。在示兩個變量a和b之和,定義一個函數(shù)來實現(xiàn)兩個變量之和。修改后,代碼如下所示:

#!/usr/bin/python3
#coding=utf-8

a = 10
b = 20

def sum(a, b):
    return (a+b)

c = sum(a, b)
print("The value of c is  ", c)

使用 git diff 命令查看更改,如下所示:

bjpowernode@ubuntu:~/git/sample$ git diff
diff --git a/main.py b/main.py
index 25eb22b..e84460d 100644
--- a/main.py
+++ b/main.py
@@ -7,5 +7,9 @@ print ("Life is short, you need Python !")
 a = 10

 b = 20
-c = a + b
-print("The value of c is  ", c)
\ No newline at end of file
+
+def sum(a, b):
+    return (a+b)
+
+c = sum(a, b)
+print("The value of c is  ", c)
bjpowernode@ubuntu:~/git/sample$

經(jīng)過測試,代碼沒有問題,提交了上面的更改。

bjpowernode@ubuntu:~/git/sample$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   main.py

no changes added to commit (use "git add" and/or "git commit -a")

bjpowernode@ubuntu:~/git/sample$ git add main.py
bjpowernode@ubuntu:~/git/sample$ git commit -m "add a new function sum(a,b)"
[master 01c5462] add a new function sum(a,b)
 1 file changed, 6 insertions(+), 2 deletions(-)
bjpowernode@ubuntu:~/git/sample$

再次查看提交記錄信息:

bjpowernode@ubuntu:~/git/sample$ git log
commit 01c54624879782e4657dd6c166ce8818f19e8251
Author: minsu 
Date:   Sun Jul 9 19:01:00 2017 -0700

    add a new function sum(a,b)

commit 51de0f02eb48ed6b84a732512f230028d866b1ea
Author: your_name 
Date:   Fri Jul 7 23:04:16 2017 +0800

    add the sum of a & b
....

經(jīng)過上面添加和提交修改后,其它開發(fā)人員并不能看到代碼中定義的 sum(a, b) 函數(shù),還需要將這里提交的本地代碼推送到遠(yuǎn)程存儲庫。使用以下命令:

bjpowernode@ubuntu:~/git/sample$ git push origin master
Username for 'http://git.oschina.net': 769728683@qq.com
Password for 'http://769728683@qq.com@git.oschina.net':<你的帳號的密碼>
Counting objects: 3, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 419 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://git.oschina.net/bjpowernode/sample.git
   51de0f0..01c5462  master -> master
bjpowernode@ubuntu:~/git/sample$

現(xiàn)在,代碼已經(jīng)成功提交到遠(yuǎn)程存儲庫中了,只要其它開發(fā)人員使用 git clone 或 git pull 就可以得到這些新提交的代碼了。

下面我們將學(xué)習(xí)其它一些更為常用的 git 命令,經(jīng)過下面的學(xué)習(xí),你就可以使用這些基本的git操作命令來文件和代碼管理和協(xié)同開發(fā)了。

添加新函數(shù)

在開發(fā)人員B(minsu)修改文件main.py中的代碼的同時,開發(fā)人員A(maxsu)在文件main.py中實現(xiàn)兩個變量的乘積函數(shù)。 修改后,main.py文件如下所示:

#!/usr/bin/python3
#coding=utf-8

print ("Life is short, you need Python !")


a = 10

b = 20
c = a + b
print("The value of c is  ", c)

def mul(a, b):
    return (a * b)

現(xiàn)在修改完代碼,運行以下命令:

$ git diff

得到如下結(jié)果:

現(xiàn)在添加并提交上面的代碼:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   main.py

no changes added to commit (use "git add" and/or "git commit -a")

$ git add main.py

Administrator@MY-PC /D/worksp/sample (master)
$ git commit -m "add a mul(a, b) function"
[master e5f8dfa] add a mul(a, b) function
 1 file changed, 4 insertions(+), 1 deletion(-)

現(xiàn)在查看上提交的日志信息,如下結(jié)果:

$ git log
commit e5f8dfa9e7e89fea8813ab107e14b9b7412df2ae
Author: your_name 
Date:   Sun Jul 9 23:06:32 2017 +0800

    add a mul(a, b) function

commit 51de0f02eb48ed6b84a732512f230028d866b1ea
Author: your_name 
Date:   Fri Jul 7 23:04:16 2017 +0800

    add the sum of a & b
... ...

好了,現(xiàn)在要將上面的代碼推送到遠(yuǎn)程存儲庫,使用以下命令:

$ git push origin master

執(zhí)行上面命令,結(jié)果如下:

$ git push origin master
Username for 'http://git.oschina.net': 769728683@qq.com
Password for 'http://769728683@qq.com@git.oschina.net':
To http://git.oschina.net/bjpowernode/sample.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'http://git.oschina.net/bjpowernode/sample.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

但Git推送失敗。因為Git確定遠(yuǎn)程存儲庫和本地存儲庫不同步。為什么呢?因為在向文件main.py添加以下代碼片段時:

def mul(a, b):
    return (a * b)

另外一個開發(fā)人員B已經(jīng)向遠(yuǎn)程存儲庫推送修改的代碼,所以這里在向遠(yuǎn)程存儲庫推送代碼時,發(fā)現(xiàn)上面的新的推送代碼,現(xiàn)在這個要推送的代碼與遠(yuǎn)程存儲庫中的代碼不一致,如果強行推送上去,Git不知道應(yīng)該以誰的為準(zhǔn)了。

所以,必須先更新本地存儲庫,只有在經(jīng)過此步驟之后,才能推送自己的改變。

獲取最新更改

執(zhí)行g(shù)it pull命令以將其本地存儲庫與遠(yuǎn)程存儲庫同步。

$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From http://git.oschina.net/bjpowernode/sample
   51de0f0..01c5462  master     -> origin/master
Auto-merging main.py
CONFLICT (content): Merge conflict in main.py
Automatic merge failed; fix conflicts and then commit the result.

現(xiàn)在打開 main.py 內(nèi)容如下:

#!/usr/bin/python3
#coding=utf-8

print ("Life is short, you need Python !")


a = 10

b = 20
<<<<<<< HEAD
c = a + b
print("The value of c is  ", c)

def mul(a, b):
    return (a * b)
=======

def sum(a, b):
    return (a+b)

c = sum(a, b)
print("The value of c is  ", c)
>>>>>>> 01c54624879782e4657dd6c166ce8818f19e8251

拉取操作后,檢查日志消息,并發(fā)現(xiàn)其它開發(fā)人員的提交的詳細(xì)信息,提交ID為:01c54624879782e4657dd6c166ce8818f19e8251

打開 main.py 文件,修改其中的代碼,修改完成后保文件,文件的代碼如下所示:

#!/usr/bin/python3
#coding=utf-8

print ("Life is short, you need Python !")

a = 10
b = 20

c = a + b
print("The value of c is  ", c)

def mul(a, b):
    return (a * b)

def sum(a, b):
    return (a+b)

c = sum(a, b)
print("The value of c is  ", c)

再次添加提交,最后推送,如下命令:

$ git add main.py

Administrator@MY-PC /D/worksp/sample (master|MERGING)
$ git commit -m "synchronized with the remote repository "
[master ef07ab5] synchronized with the remote repository

Administrator@MY-PC /D/worksp/sample (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

Administrator@MY-PC /D/worksp/sample (master)
$ git push origin master
Username for 'http://git.oschina.net': 769728683@qq.com
Password for 'http://769728683@qq.com@git.oschina.net':
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 657 bytes | 0 bytes/s, done.
Total 6 (delta 2), reused 0 (delta 0)
To http://git.oschina.net/bjpowernode/sample.git
   01c5462..ef07ab5  master -> master

現(xiàn)在,一個新的代碼又提交并推送到遠(yuǎn)程存儲庫中了。

全部教程
主站蜘蛛池模板: 精品视频在线观看一区二区 | 久久77777 | 国产aav| 日韩精品麻豆 | 国产在线精品二区赵丽颖 | 亚洲乱强| 黄在线免费看 | 欧美色亚洲图 | 一级做a爱片久久蜜桃 | 操美女穴 | 91精品国产99久久 | 国产一级成人毛片 | 日本爱爱视频网站 | 奇米影视一区二区三区 | 婷婷视频网站 | 伊人三区| 久久久久久国产精品免费 | 中文字幕在线观看免费视频 | 色黄网站青青草原免费 | 亚洲福利精品一区二区三区 | 久久精品蜜芽亚洲国产a | 午夜按摩| 国产精品三区四区 | 久久99爱视频 | 五月久久亚洲七七综合中文网 | 国产免费私人影院永久免费 | 99视频国产热精品视频 | 日日干夜夜骑 | 美女超逼 | 国产精品亚洲精品日韩已满 | 一及黄色毛片 | 五月婷婷六月激情 | 羞羞的视频在线免费观看 | 国产日韩在线看 | 久久久久久亚洲精品不卡 | 四色婷婷 | 久草热在线 | 国产永久一区二区三区 | h片在线观看 | 91正在播放极品白嫩在线观看 | 99精品国产兔费观看66 |