git 入門總結

git 總結

https://www.cnblogs.com/zengsf/p/9709484.html

git初始化倉庫

## Git 全局設置
git config --global user.name  "wkkkkkkkkk"
git config --global user.email "[email protected]"

## 創建新版本庫
git clone https://code.aliyun.com/yes5144/GoDevops.git
cd GoDevops
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

## 已存在的文件夾或 Git 倉庫
cd existing_folder
git init
git remote add origin https://code.aliyun.com/yes5144/GoDevops.git
git add .
git commit
git push -u origin master

git第一次克隆

## 普通clone
git clone https://code.aliyun.com/yes5144/GoDevops.git

## 通過ssh祕鑰,上傳自己的祕鑰後,可以實現免祕鑰上傳和下載
git clone [email protected]:yes5144/GoDevops.git

git第一次提交

## 添加全部
git add . 
## 添加指定文件
git add README.md
## git commit -m 'your description'

git版本回退

## 回到上一個版本,如果想要回到前兩個版本,就在HEAD後面用兩個^^
git reset --hard HEAD^
## 回到指定版本,這裏用git reflog配合好使用
git reset --hard commit_id

-----------------------
## 操作需謹慎,記得備份
git reset --hard HEAD~1 
git add . 
git commit -m 'roll-back'
git push -f origin master

check分支

git合併分支

git merge 

git merge

放棄本地修改,並遠程覆蓋本地

## 建議閱讀此鏈接後再謹慎操作:https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files
本地有修改和提交,如何強制用遠程的庫更新更新。我嘗試過用git pull -f,總是提示 You have not concluded your merge. (MERGE_HEAD exists)。
我需要放棄本地的修改,用遠程的庫的內容就可以,應該如何做?傻傻地辦法就是用心的目錄重新clone一個,正確的做法是什麼?

## 正確的做法應該是:
git fetch origin master
git reset --hard origin/master
## git fetch 只是下載遠程的庫的內容,不做任何的合併
## git reset 把HEAD指向剛剛下載的最新的版本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章