您好,登錄后才能下訂單哦!
本篇內容主要講解“Git有什么常用的命令”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Git有什么常用的命令”吧!
功能:克隆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
完成后,已經存在git
倉。
如果本地代碼沒有git
倉,可使用git init
命令初始化空的git
倉。
功能:初始化本地倉,命令執行完后生成.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/
功能:檢查當前文件狀態。
格式: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
狀態。
功能:跟蹤文件。
格式: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 ## 新增文件沒有被跟蹤
功能:提交更新。
格式: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"
功能:忽略文件
在git
倉目錄下編輯.gitignore
文件,忽略不需要納入git
倉管理的文件,例:編譯后生成的.o
等文件。
## 1.新建1.o測試文件,git status查看文件狀態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.查看文件狀態時,沒有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有什么常用的命令”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。