溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Git有什么常用的命令

發(fā)布時間:2021-07-08 17:38:49 來源:億速云 閱讀:216 作者:chen 欄目:互聯(lián)網(wǎng)科技

本篇內(nèi)容主要講解“Git有什么常用的命令”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Git有什么常用的命令”吧!

1、git clone

功能:克隆git倉。

格式:git clone url

用法:

## clone rockpi代碼,下載完成后,代碼存儲在rockchip-bsp文件夾git clone --recursive https://github.com/radxa/rockchip-bsp.git## clone rockpi代碼,下載完成后,代碼存儲在rockpi文件夾git clone --recursive https://github.com/radxa/rockchip-bsp.git rockpi

clone完成后,已經(jīng)存在git倉。

如果本地代碼沒有git倉,可使用git init命令初始化空的git倉。

2、git init

功能:初始化本地倉,命令執(zhí)行完后生成.git文件夾。用于新建本地git倉,進行代碼管理。

格式:git init

用法:

root@ubuntu:/home/run/code/libdrm-2.4.89# git initInitialized empty Git repository in /home/run/code/libdrm-2.4.89/.git/
3、git status

功能:檢查當前文件狀態(tài)。

格式:git status

用法:

root@ubuntu:/home/run/code/libdrm-2.4.89# git statusOn branch masterNo commits yetUntracked files:  (use "git add <file>..." to include in what will be committed)        Makefile.am        Makefile.in        Makefile.sources        README        aclocal.m4        amdgpu/        ...

注:由于是本地新建git倉,此時文件屬于Untracked狀態(tài)。

4、git add

功能:跟蹤文件。

格式:git add

用法:

root@ubuntu:/home/run/code/libdrm-2.4.89# git add .root@ubuntu:/home/run/code/libdrm-2.4.89# git statusOn branch masterNo commits yetChanges to be committed:  (use "git rm --cached <file>..." to unstage)        new file:   Makefile.am        new file:   Makefile.in        new file:   Makefile.sources        new file:   README        new file:   aclocal.m4        new file:   amdgpu/Makefile.am

注:

1)git add filename:跟蹤名為filename的文件。

2)git add -u:跟蹤被修改或刪除文件,不包括新增文件。

3)git add .:跟蹤所有變化,等同git add -A。

## 1.刪除git倉中的README,新增加readme.txtroot@ubuntu:/home/run/code/test/libdrm-2.4.89# rm READMEroot@ubuntu:/home/run/code/test/libdrm-2.4.89# touch readme.txtroot@ubuntu:/home/run/code/test/libdrm-2.4.89# git statusOn branch masterChanges not staged for commit:  (use "git add/rm <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)        deleted:    READMEUntracked files:  (use "git add <file>..." to include in what will be committed)        readme.txtno changes added to commit (use "git add" and/or "git commit -a")## 2. git add . :跟蹤所有變化,和 git add -A 相同root@ubuntu:/home/run/code/test/libdrm-2.4.89# git add .root@ubuntu:/home/run/code/test/libdrm-2.4.89# git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)        deleted:    README        new file:   readme.txt## 3. 回退到步驟1root@ubuntu:/home/run/code/test/libdrm-2.4.89# git reset HEAD READMEUnstaged changes after reset:D       READMEroot@ubuntu:/home/run/code/test/libdrm-2.4.89# git reset HEAD readme.txtUnstaged changes after reset:D       READMEroot@ubuntu:/home/run/code/test/libdrm-2.4.89# git statusOn branch masterChanges not staged for commit:  (use "git add/rm <file>..." to update what will be committed)  (use "git checkout -- <file>..." to discard changes in working directory)        deleted:    READMEUntracked files:  (use "git add <file>..." to include in what will be committed)        readme.txtno changes added to commit (use "git add" and/or "git commit -a")## 4. git add -uroot@ubuntu:/home/run/code/test/libdrm-2.4.89# git add -uroot@ubuntu:/home/run/code/test/libdrm-2.4.89# git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)        deleted:    READMEUntracked files:  (use "git add <file>..." to include in what will be committed)        readme.txt    ## 新增文件沒有被跟蹤
5、git commit

功能:提交更新。

格式:git commit

用法:

root@ubuntu:/home/run/code/libdrm-2.4.89# git commit -m "Init code"[master (root-commit) bfa9cc1] Init code 337 files changed, 156347 insertions(+) create mode 100644 Makefile.am create mode 100644 Makefile.in create mode 100644 Makefile.sources create mode 100644 README create mode 100644 aclocal.m4 create mode 100644 amdgpu/Makefile.am

注:

1)git commit:啟動文本編輯器,輸入提交說明。文本編輯器使用git config指定,可參考前一篇文章。

2)git commit -m “...”:在-m后輸入提交信息,直接提交。

3)git commit --amend:對上次提交的信息進行修改。

例:

新建本地libdrm-2.4.89 代碼git倉方法如下:

root@ubuntu:/home/run/code/libdrm-2.4.89# git initroot@ubuntu:/home/run/code/libdrm-2.4.89# git add .root@ubuntu:/home/run/code/libdrm-2.4.89# git commit -m "Init code"
6、.gitignore

功能:忽略文件

git倉目錄下編輯.gitignore文件,忽略不需要納入git倉管理的文件,例:編譯后生成的.o等文件。

## 1.新建1.o測試文件,git status查看文件狀態(tài)root@ubuntu:/home/run/code/libdrm-2.4.89# touch 1.oroot@ubuntu:/home/run/code/libdrm-2.4.89# git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)        deleted:    README        new file:   readme.txtUntracked files:  (use "git add <file>..." to include in what will be committed)        1.o## 2.編輯.gitignoreroot@ubuntu:/home/run/code/libdrm-2.4.89# vi .gitignoreroot@ubuntu:/home/run/code/test/libdrm-2.4.89# cat .gitignore*.o## 3.查看文件狀態(tài)時,沒有1.o文件root@ubuntu:/home/run/code/libdrm-2.4.89# git statusOn branch masterChanges to be committed:  (use "git reset HEAD <file>..." to unstage)        deleted:    README        new file:   readme.txtUntracked files:  (use "git add <file>..." to include in what will be committed)        .gitignore

到此,相信大家對“Git有什么常用的命令”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

git
AI