1.指令
git config --global user.email "[email protected]"
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 "[email protected]"//三次回車
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 [email protected]
測試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