1. 程式人生 > >【git】git的基本使用

【git】git的基本使用

一,git的配置如下所示:

https://blog.csdn.net/Hanani_Jia/article/details/77950594

總結:

先在github上註冊申請賬戶並建立專案;

然後安裝軟體工具Git Bash;使用Bash生成公鑰:ssh-keygen-t rsa-C "[email protected]";

接著將公鑰.pub複製到github的“SSH Keys”上。並返回到Bash使用"ssh -T [email protected]"來檢查是否繫結成功。

然後使用"git config --global user.name "youname"" 和"git config --global user.email "youemail""來 繫結郵箱。

這樣就可以操作git了。

二,git的基本操作

git clone $git_address; 獲取新的git專案。

git pull; 更新已有的git專案。

git status; 檢視當前git專案與遠端倉庫的變化;

git add $file; 增加發生改變的或者新的檔案;         

git rm $file; 將遠端倉庫中的檔案去除掉;

git commit -m "說明";  本地專案改變的檔案加到暫存區中;

git push origin $branch;   將從暫存區的檔案推送到遠端倉庫中。$branch 可以是某個分支,也可以是master。

git checkout $branck; 專案切換到分支中去。

git checkout  -b $branck; 建立新的專案分支並切換到該分支中去。

git push origin --delete $dev_branch; 刪除分支。

-----

git diff $file; 比較工作區與暫存區的檔案。

git diff HEAD $file; 工作區與HEAD(當前工作分支)的比較。

git diff $branch_name $file; 當前分支的檔案與branch_name的比較。

git diff commitID file; 工作區與某一次提交的比較。

-----

合併程式碼:在切換到master之後

git merge $branchname --no-ff

然後提交:git push origin master

 

參考連結:https://blog.csdn.net/zangxueyuan88/article/details/81078879

https://blog.csdn.net/Hanani_Jia/article/details/77950594