1.指令
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git init -- 创建一个空的 Git 仓库或重新初始化一个已存在的仓库
git init
> Initialized empty Git repository in /root/code/repo/controller/.git/
// 添加单个文件
git add test.txt
// -- 添加所有文件
git add .
//在执行commit之前,git config将邮箱和名字配置好。
git commit -m
git status
//配置远程代码仓库
git remote add origin **** //****远程代码仓库地址
git remote -v //查看是否成功
git clone ssh://******
git pull origin master
git push origin master
git checkout 1.15.3
git log //可加--pretty=oneline
git log -3 //查看最近三次的提交
git mergetool --tool=vimdiff3 //解决冲突选择工具
pull强行合并
root@ubuntu:~/code/repo/controller# git pull origin master --allow-unrelated-histories
From xxxxxxxx/uc4
* branch master -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
解决冲突mergetool 错误:
git mergetool
ubuntu The merge tool bc is not available as 'bcompare'
2.生成添加ssh公钥私钥
ssh-keygen -t rsa -C "you@example.com"//三次回车
root@ubuntu:~/code/repo/controller# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): controllerKey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in controllerKey.
Your public key has been saved in controllerKey.pub.
The key fingerprint is:
54:27:25:a5:47:0c:1b:31:9f:40:06:2d:82:3b:6f:c9 root@ubuntu
The key's randomart image is:
+--[ RSA 2048]----+
| . .+%*= |
| . . .o.%.. |
| . ...o + |
| o . . |
| + .S |
| E |
| . |
| |
| |
+-----------------+
controllerKey 私钥,controllerKey.pub公钥。
cat controllerKey.pub
将公钥添加至远端代码仓库。
测试ssh.
ssh -T git@github.com
测试ssh不成功,但是git clone可以下载。
3.忽略文件
cat .gitignore
文件 .gitignore
的格式规范如下:
- 所有空行或者以注释符号
#
开头的行都会被 Git 忽略。 - 可以使用标准的 glob 模式匹配。
- 匹配模式最后跟反斜杠(
/
)说明要忽略的是目录。 - 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(
!
)取反。
所谓的 glob 模式是指 shell 所使用的简化了的正则表达式。星号(*)匹配零个或多个任意字符;[abc]匹配任何一个列在方括号中的字符(这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c);问号(?)只匹配一个任意字符;如果在方括号中使用短划线分隔两个字符,表示所有在这两个字符范围内的都可以匹配(比如 [0-9] 表示匹配所有 0 到 9 的数字)。
我们再看一个 .gitignore 文件的例子:
# 此为注释 – 将被 Git 忽略
# 忽略所有 .a 结尾的文件
*.a
# 但 lib.a 除外
!lib.a
# 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
/TODO
# 忽略 build/ 目录下的所有文件
build/
# 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
doc/*.txt
# 忽略 doc/ 目录下所有扩展名为 txt 的文件
doc/**/*.txt