一:準備工作:
1.建立庫文件夾:repository,用戶文件夾develop
2.$ cd c: $ cd software/ 清屏(ctrl + l 或clear)$ cd repository/ 然後初始化倉庫:
git init --bare shared.git
在develop文件夾下建立兩個用戶:user1 user2
將c盤下的庫文件shared.git複製到user1中
$ cd ..
$ cd develop/user1
$ git clone /c/software/repository/shared.git .
創建文件:$ echo "user1 create the file fuck" >index.jsp
vim index.jsp
3.改變爲修改模式:按i鍵:
4.修改後按esc退出修改模式,按:保存,wq退出,強制退出:!q
5.查看修改的情況:
$ cat index.jsp
user1 create the file fuck
user1 update the fuck file
6.提交修改:
$ git config user.name "user1"
$ git config user.email "[email protected]"
$ git add index.jsp
$ git commit
7.將本地代碼上傳到遠端的服務器:
$ git push origin master
二:新開一個git bash窗口,爲user2 clone 庫文件:
$ cd c:
$ cd software/develop/user2
$ git clone /c/software/repository/shared.git .
可以看到user2文件夾下有與user1文件夾下相同的文件。
且內容相同:
$ cat index.jsp
user1 create the file fuck
user1 update the fuck file
1.User2修改:
vim index.jsp
2.查看修改的情況:
$ cat index.jsp
user1 create the file fuck
user1 update the fuck file
user2 update the file ~~~~
3.提交修改:
$ git config user.name "user2"
$ git config user.email "[email protected]"
$ git add index.jsp
$ git commit
4.提交到遠程服務器:
$ git push origin master
三:user1查看user2的更新情況:
$ git pull
1.User1修改:
$ echo "user1 update" >>index.jsp
$ cat index.jsp
user1 create the file fuck
user1 update the fuck file
user2 update the file ~~~~
user1 update
2.User1提交修改:
$ git add index.jsp
$ git commit -m "user1 update"
通過以上的方式,可以實現開發人員1 與開發人員2的交互過程。