上一篇文章“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.old System.map autoconf.h /tools/mkimage /u-boot /u-boot.map /u-boot.srec /uboot.bin /uboot.img uboot_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 config linye@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.c nothing added to commit but untracked files present (use "git add" to track)
接着就使用git add
、git commit
、git 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 -s 1.Add .gitignore 2.Add .config for XiaomiRoutermini 3.Add httpd/fsdata.c Signed-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 #
使用tig
和git 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.c linye@ubuntu:~/XiaomiRouter/U-boot$ tig linye@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 master Username for 'https://github.com': creator_ly@163.com Password for 'https://creator_ly@163.com@github.com': To https://github.com/XiaomiRouter/U-boot.git 8fe85af..0c81c2f master -> master
登陆GitHub查看commit是否有上传即可。
Git提交时的优化的分析就到这边,有感悟时会持续会更新。