一、clone代码
这部分可参考本系列之三,这里不再赘述。
二、修改代码并查看仓库状态(status)
这里仅以增加一个已有目录include/net为例来说明。
[qxhgd@localhost linux-net-kernel]$ mkdir inlcude [qxhgd@localhost linux-net-kernel]$ cp -afr /home/qxhgd/code/linux-4.19.157/include/net ./inlcude/net [qxhgd@localhost linux-net-kernel]$ git status # On branch main # Untracked files: # (use "git add <file>..." to include in what will be committed) # # inlcude/ nothing added to commit but untracked files present (use "git add" to track)
三、向暂存库增加文件(add)
[qxhgd@localhost linux-net-kernel]$ git add .
四、增加提交信息(commit)
两种方式:
[qxhgd@localhost linux-net-kernel]$ git commit [main 9533960] [docs]-[add include/net into linux-net-kernel directory] 317 files changed, 81135 insertions(+) create mode 100644 linux-net-kernel/inlcude/net/6lowpan.h ...
或:
[qxhgd@localhost linux-net-kernel]$ git commit -m "[docs]-[add include/net into linux-net-kernel directory]"
两者的区别:
- 前者:
执行后,需额外在vim界面中输入提交的注释信息;
可输入多行注释信息;
- 后者:
直接在-m后带相关注释信息;
仅支持一行注释信息;
如需要输入多行,则需要多个-m选项,如:
git -m “commit title” -m “commit description”。
五、提交代码(push)
[qxhgd@localhost linux-net-kernel]$ git push warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'. To squelch this message and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information. (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 'current' instead of 'simple' if you sometimes use older versions of Git) Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts. Counting objects: 336, done. Compressing objects: 100% (332/332), done. Writing objects: 100% (334/334), 720.95 KiB | 0 bytes/s, done. Total 334 (delta 11), reused 0 (delta 0) remote: Resolving deltas: 100% (11/11), completed with 1 local object. To git@github.com:qxhgd/Reading-and-comprehense-linux-Kernel-network-protocol-stack-4.19.157.git 08e97a5..9533960 main -> main
有些情况下会报下面的错误:
No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'master'. Everything up-to-date
可用下面命令替换:
git push origin master