该文档不定时更新,如有需要请收藏。
嵌入式开发过程中,也经常使用git进行版本管理,根据项目需求对git的使用程度不一样。这里介绍一种,git的简单使用,可以满足大部分的嵌入式开发,可以说嵌入式开发使用git后,可以基本拜托掉之前的的压缩保存版本,使用比较软件进行代码比较的方式。
这里使用git管理linux内核为例做如下说明:网上下载一个版本的linux内核,解压到本地文件夹。
建设本地库
首先创建.gitignore文件,这里很多教程都忽略这一步,是非常不应该的,尤其针对比较庞大的工程,编译出来很多.o等等过程文件,这些我们不需要进行版本管理,所以这里针对不需要的文件进行筛选
查看所有文件
ls -a

这里已经有了.gitignore
查看一下,文件比较长,下图没有完全罗列出来,这里的. gitignore是针对linux内核的使用的,我们实际的工程可以参考该gitignore文件修改。我们的工程很少有比linux内核更复杂的,所以参考这个gitignore文件是很有帮助的。
cat .gitignore

如果您的工程没有.gitignore
则需要在当前文件夹下创建gitignore
touch .gitignore
编辑.gitignore
sudo gedit .gitignore

下面的步骤都是比较常规的,依次输入即可
初始化本地代码仓库
git init
初始化完成,进去创建的文件夹,在本地创建一个文件,添加到版本控制
git add .
查看状态
git status
添加进去,再去查看状态就会看没有文件可以提交了< -m: 表示提交本版本代码的信息>
git commit -m “v1.0”
查看日志
git log
用户名: git config --global user.name "用户名"
邮箱: git config --global user.email "邮箱"
查看日志: git log / git log --oneline(一行显示一条日志)
初始化git仓库,提前创建好.gitignore
查看不同
git diff
查看版本信息
git log
这里提供一下.gitignore参考
- #
- # NOTE! Don't add files that are generated in specific
- # subdirectories here. Add them in the ".gitignore" file
- # in that subdirectory instead.
- #
- # NOTE! Please use 'git ls-files -i --exclude-standard'
- # command after changing this file, to see if there are
- # any tracked files which get ignored after the change.
- #
- # Normal rules
- #
- .*
- *.o
- *.o.*
- *.a
- *.s
- *.ko
- *.so
- *.so.dbg
- *.mod.c
- *.i
- *.lst
- *.symtypes
- *.order
- *.elf
- *.bin
- *.tar
- *.gz
- *.bz2
- *.lzma
- *.xz
- *.lz4
- *.lzo
- *.patch
- *.gcno
- *.ll
- modules.builtin
- Module.symvers
- *.dwo
- *.su
- *.c.[012]*.*
-
- #
- # Top-level generic files
- #
- /tags
- /TAGS
- /linux
- /vmlinux
- /vmlinux.32
- /vmlinux-gdb.py
- /vmlinuz
- /System.map
- /Module.markers
-
- #
- # Debian directory (make deb-pkg)
- #
- /debian/
-
- #
- # tar directory (make tar*-pkg)
- #
- /tar-install/
-
- #
- # git files that we don't want to ignore even if they are dot-files
- #
- !.gitignore
- !.mailmap
- !.cocciconfig
-
- #
- # Generated include files
- #
- include/config
- include/generated
- arch/*/include/generated
-
- # stgit generated dirs
- patches-*
-
- # quilt's files
- patches
- series
-
- # cscope files
- cscope.*
- ncscope.*
-
- # gnu global files
- GPATH
- GRTAGS
- GSYMS
- GTAGS
-
- # id-utils files
- ID
-
- *.orig
- *~
- \#*#
-
- #
- # Leavings from module signing
- #
- extra_certificates
- signing_key.pem
- signing_key.priv
- signing_key.x509
- x509.genkey
-
- # Kconfig presets
- all.config
-
- # Kdevelop4
- *.kdev4