日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Git 初步学习

發(fā)布時間:2023/11/29 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Git 初步学习 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

學習目標

在linux 上安裝Git 服務器

在windows 上安裝 Git 客戶端

創(chuàng)建Git倉庫,git用戶

在windows 中獲取項目,對項目進行增刪改查,更新到服務器

創(chuàng)建兩個分支,進行分支修改和代碼合并

1. 在linux上安裝git服務器

  使用指令:sudo apt-get install git

  安裝完成效果:

stark@ubuntu:~$ git --version git version 2.7.4 

2. 安裝Git客戶端,下載Git for Windows,安裝完成運行Git Bash 輸入指令

$ git --version git version 2.15.0.windows.1

3. 服務器端創(chuàng)建Git 倉庫

stark@ubuntu:~/data/git$ mkdir gittest.git stark@ubuntu:~/data/git$ git init gittest.git Initialized empty Git repository in /home/stark/data/git/gittest.git/.git/

  以為git 默認禁止push代碼需要配置 .git/config 文件添加 (push失敗后,網(wǎng)上查詢)

[receive]denyCurrentBranch = ignore

  添加git用戶和git用戶組,并且修改權限

#創(chuàng)建用戶組 sudo groupadd gituser #創(chuàng)建用戶 sudo useradd gituser -g gituser sudo passwd gituser sudo mkdir /home/gituser sudo chown -R gituser /home/gituser #修改git倉庫權限 sudo chown -R gituser.gituser gittest.git

4. 客戶端抓取項目,進行增刪改查

# 下載項目 $ git clone gituser1@192.168.195.149:/home/stark/data/git/gittest.git Cloning into 'gittest'... gituser1@192.168.195.149's password: warning: You appear to have cloned an empty repository. $ git init gittest/ Reinitialized existing Git repository in D:/GitTest/gittest/.git/ #創(chuàng)建文件,上傳 $ echo "hellohit">hello.txt $ git add hello.txt $ git commit -m 'hello' $ git push origin master #修改文件,上傳 $ echo 'hellogit' >hello.txt $ git add hello.txt $ git commit -m 'modify' $ git push origin master #在另一處確認修改 $ git pull #刪除文件 $ rm hello.txt $ git rm hello.txt $ git commit -m 'remove' $ git push origin master #查詢?nèi)罩?關鍵信息是commit id $ git log #回滾到某一版本(本地版本) $ git reset –hard <commit id>

  在倉庫下沒有發(fā)現(xiàn)上床的文件,因為git倉庫保存的是快照。在另外一處重新抓取項目,可以發(fā)現(xiàn)文件已經(jīng)被上傳了

5. 使用Git的分支功能

#添加一個空白文件 $ touch branch.txt $ git add status $ git commit -m 'add file' $ git push origin master #創(chuàng)建分支 $ git branch testing1 $ git branch testing2 #查看本地分支 $ git branch #切換到分支進行文件修改,push到遠程分支 $ git checkout testing1 $ echo 'testing1'> branch.txt $ git add branch.txt $ git commit -m 'testing1' $ git push origin testing1$ git checkout testing2 $ echo 'testing2'> branch.txt $ git add branch.txt $ git commit -m 'testing2' $ git push origin testing2 #查看遠程分支 $ git branch -r #合并分支1,上傳,刪除分支 $ git checkout master $ git merge testing1 # Fast-forward 表示沒有沖突 $ git push origin master $ git push origin --delete testing1 $ git branch -d testing1 #合并分支2,解決沖突,上傳刪除分支 $ git merge testing2 #CONFLICT 表示合并出現(xiàn)沖突 #解決沖突后像修改文件一樣上傳就行

轉載于:https://www.cnblogs.com/starktan/p/9315200.html

總結

以上是生活随笔為你收集整理的Git 初步学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。