GIT使用總結

2021-08-31 03:51:32 字數 2797 閱讀 2731

git認證指使用git能與github或gitlab 進行通訊。這裡將以github為例來說明。

1、設定姓名和郵箱位址

git config --global user.name "zhangdm"

git config --global user.email "***[email protected]"

2、設定ssh key

github上連線已有倉庫時的認證,是通過使用了ssh的公開金鑰認證方式進行的。建立ssh key,詳情見下面的博文

先在github(上建立賬號,然後建立repository,這裡不做介紹。

1、將遠端倉庫clone下來

git clone [email protected]:zhangdm/git_learn.git
2、將遠端的倉庫pull下來

git pull origin master
3、將更新後的**add到快取區

git add *
4、commit

git commit -m "更新內容"
5、push到遠端倉庫

git push -u origin master
1、建立分支test

git checkout -b test
2、切換到分支test

git checkout test
3、分支合併到master

git pull origin test

git checkout master

git merge test

常見的**衝突,如將本地**更新了,然後操作了pull,就會報衝突。博文提供了解決方案

1、先pull下來

git pull origin test
2、再來更新**

3、add **

git add *
4、commit**

git commit -m "update"
5、push到遠端伺服器

git push -u origin test
有時需要對某些檔案不做提交,這時就得使用**.gitignore**檔案,在裡面新增需要過濾的規則。如過濾pyc

*pyc

__pycache__

有時,沒有在**.gitignore**中提交某些規則,將不必要的檔案提交了,那怎麼刪除遠端的檔案呢?博文提供的一種解決方案

1、預覽將要刪除的檔案

git rm -r -n --cached 檔案/資料夾名稱

加上 -n 這個引數,執行命令時,是不會刪除任何檔案,而是展示此命令要刪除的檔案列表預覽。

2、確認無誤後刪除檔案

git rm -r --cached 檔案/資料夾名稱
3、提交到遠端伺服器

git commit -m "提交說明"

git push origin master

4、最後,修改.gitignore檔案,避免下次再次出現上傳的錯誤,然後提交

git commit -m "提交說明"

git push origin master

工作中會不經意之間將資料集也做了提交,導致專案的.git很大,然而整個專案中.git 會一直都有,勢必會麻煩。下面說下.git**的步驟。(方法來自網路)

1、第一步:找到git中前n個檔案,如前10個

會發現最後一次檔案最大,449f5b3eeaabc6e27765bfa4db99aca785b37e1a

2、第二步:找到檔名

git rev-list --objects --all | grep 449f5b3eeaabc6e27765bfa4db99aca785b37e1a
3、第三步:執行刪除操作

git filter-branch --index-filter 'git rm --cached --ignore-unmatch data/cnew.txt'
4、第四步:清理快取和刪除

注意:需要將master修改為你當前所在分支

rm -rf .git/refs/original/

git reflog expire --expire=now --all

git fsck --full --unreachable

git repack -a -d

git gc --aggressive --prune=now

git push --force origin master

Git使用總結

1.git branch vv 檢視本地分支與遠端分支的關聯關係 2.git push origin localbranch remotebranch 建立遠端分支remotebranch,該遠端分支的內容與localbranch內容一致 3.git push origin remotebranch...

Git使用總結

在linux上安裝git 命令 tar,config,make,sudo make install 在mac os x上安裝git exe程式執行即可 安裝完成後,在開始選單裡找到 git git bash 蹦出乙個類似命令列視窗的東西,就說明git安裝成功!設定使用者名稱 git config g...

Git使用總結

在windows上安裝git 安裝完成後,在開始選單裡找到 git git bash 蹦出乙個類似命令列視窗的東西,就說明git安裝成功!install git on windows安裝完成後,還需要最後一步設定,在命令列輸入 git config global user.name your nam...