本篇内容主要讲解“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。