首页 > 学院 > 开发设计 > 正文

XiaomiRouter自学之路(06-Git提交时的优化(.gitignore、git commit))

2019-11-07 23:04:23
字体:
来源:转载
供稿:网友

XiaomiRouter自学之路(06-Git提交时的优化(.gitignore、git commit))

上一篇文章“U-boot配置编译烧录”中,已经编译测试好U-boot,现在将代码更新的部分进行整合提交到GitHub,

先使用git status查看下我们编译后的工程

linye@Ubuntu:~/XiaomiRouter/U-boot$ git status# On branch master# Untracked files:# (use "git add <file>..." to include in what will be committed)## .config# System.map# autoconf.h# board/rt2880/.depend# board/rt2880/librt2880.a# board/rt2880/memsetup.o# board/rt2880/rt2880.o# board/rt2880/rt2880_init.o# board/rt2880/serial.o# common/.depend# common/cmd_bdinfo.o# common/cmd_boot.o# common/cmd_bootm.o# common/cmd_console.o# common/cmd_fat.o...

可以看到有很多的.o、.a等编译或中间文件,这些文件是编译产生的结果,我们不可能将其提交到代码库中,所以提交的时候需要将其排除,这时候就要用到.gitignore 配置文件

对于.gitignore配置文件的语法很简单,随便找个例子看下就懂,需要注意的是.gitignore配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效

linye@ubuntu:~/XiaomiRouter/U-boot$ vim .gitignore*.o*.a*.depend/.config/.config.oldSystem.mapautoconf.h/tools/mkimage/u-boot/u-boot.map/u-boot.srec/uboot.bin/uboot.imguboot_128k.bin

添加完以上信息后,我们再查看status,只有以下两个文件了

linye@ubuntu:~/XiaomiRouter/U-boot$ git status# On branch master# Untracked files:# (use "git add <file>..." to include in what will be committed)## .gitignore# httpd/fsdata.c

httpd/fsdata.c是新产生的一个文件先留着,这边把.config也不做上传,是因为一般.config是根据每个人各自的平台去选的配置,所以常用的做法就是将自己的.config做一个备份,别人clone你的仓库后,如果跟你的平台一样,那就在备份里面cp你的.config,不同的话则需要他自己再配置一遍,如下做法:

linye@ubuntu:~/XiaomiRouter/U-boot$ mkdir configlinye@ubuntu:~/XiaomiRouter/U-boot$ cp .config config/XiaomiRoutermini

现在我们的git status变成如下

linye@ubuntu:~/XiaomiRouter/U-boot$ git status# On branch master# Untracked files:# (use "git add <file>..." to include in what will be committed)## .gitignore# config/# httpd/fsdata.cnothing added to commit but untracked files PResent (use "git add" to track)

接着就使用git addgit commitgit push等动作进行提交,但是我们上一次使用的是git commit -m来填写修改记录,发现很不直观,而且如果我想写多条的时候就更不方便了,所以我们使用vim来进行编辑记录信息,我们打开在./.git/config里面添加editor = vim即可,如下

linye@ubuntu:~/XiaomiRouter/U-boot$ vim ./.git/config[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true editor = vim

接下去我们就可以使用git commit -s来提交记录信息,如下:

linye@ubuntu:~/XiaomiRouter/U-boot$ git commit -s1.Add .gitignore2.Add .config for XiaomiRoutermini3.Add httpd/fsdata.cSigned-off-by: ye.lin <creator_ly@163.com># Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: .gitignore# new file: config/XiaomiRoutermini# new file: httpd/fsdata.c#

使用tiggit status查看下提交是否正确,正确则使用git push origin master到GitHub

linye@ubuntu:~/XiaomiRouter/U-boot$ git commit -s[master 0c81c2f] 1.Add .gitignore 2.Add .config for XiaomiRoutermini 3.Add httpd/fsdata.c 3 files changed, 504 insertions(+) create mode 100644 .gitignore create mode 100644 config/XiaomiRoutermini create mode 100644 httpd/fsdata.clinye@ubuntu:~/XiaomiRouter/U-boot$ tiglinye@ubuntu:~/XiaomiRouter/U-boot$ git status# On branch master# Your branch is ahead of 'origin/master' by 1 commit.#nothing to commit (working directory clean)linye@ubuntu:~/XiaomiRouter/U-boot$ git push origin masterUsername for 'https://github.com': creator_ly@163.comPassWord for 'https://creator_ly@163.com@github.com':To https://github.com/XiaomiRouter/U-boot.git 8fe85af..0c81c2f master -> master

登陆GitHub查看commit是否有上传即可。

Git提交时的优化的分析就到这边,有感悟时会持续会更新。

注:以上内容都是本人在学习过程积累的一些心得,难免会有参考到其他文章的一些知识,如有侵权,请及时通知我,我将及时删除或标注内容出处,如有错误之处也请指出,进行探讨学习。文章只是起一个引导作用,详细的数据解析内容还请查看XiaomiRouter相关教程,感谢您的查阅。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表