git
git 指令:
git init 初始化本地git環境
git clone XXX 克隆一份代碼到本地倉庫
git pull 把遠程庫的代碼更新到工作臺
git pull origin master 強制把遠程庫的代碼跟新到當前分支上面
git fetch 把遠程庫的代碼更新到本地庫
git add . 把本地的修改加到stage中
git commit -m ‘comments here’ 把stage中的修改提交到本地庫
git push 把本地庫的修改提交到遠程庫中
git branch 查看分支
$ git branch iss53 創建分支
git checkout -b fuwuqi 創建並切換分支
git 配置自己身份: 設置username 和 pass:
1. $ git config --global user.name "Colaplusice"
2. git config --global user.email "[email protected]"
遠程倉庫
git remote rm origin
刪除遠程倉庫git clone https://github.com/Colaplusice/myweb.git
將項目從遠程倉庫拷貝下來git remote -V
查看遠程倉庫- 添加遠程倉庫
git remote add origin https://github.com/Colaplusice/JN.git
- 將遠程倉庫內容全部更新下來
git pull https://github.com/Colaplusice/myweb.git
https://github.com/Colaplusice/django_1.git
將 文件夾提交到遠程倉庫
git push -u origin master
git push -u origin master -f 強制提交 刪除Git上的文件
git將本地文件上傳到github
git init git add . git commit -m "first commit" git remote add origin https://github.com/Colaplusice/JN.git git push -u origin master
衝突
push失敗 因爲遠程倉庫已經有內容所以不能直接push
解決辦法: 先pull下來,pull的時候再後面加命令 –allow-unrelated-histories
然後再push上去
pull失敗,放棄本地文件:
git fetch –all
git reset –hard origin/masterpull 失敗,保留本地文件
git stash
git pull
git stash pop
丟掉遠端的內容,強制push
刪除遠端內容:git remote rm origin
強制提交:git push origin master –force
分支
git push origin Mac_branch:Mac_branch 推送本地分支到遠程分支
clone 分支內容
git clone -b 分支名 倉庫地址
切換到主分支併合並
git checkout master
git merge hotfix
git 分支合併
刪除分支
git branch -d hotfix查看出現衝突的地方
git status
git 取回遠程分支再合併
git fetch origin master
git merge
next 爲分支名稱
git pull origin next:master
爲什麼會產生衝突
本地內容和遠程不一樣
然後從遠程pull下來竟然不覆蓋?
那 遠程內容和本地不一樣,本地push怎麼不會產生衝突…
應該是 本地 多了一個a 文件夾, 如果pull的話,a就要被刪掉
所以有衝突
git 解決衝突的辦法
ubuntu settings 是最新的
其他不是
從 master pull下來
settings產生了衝突
不用管 git add .
commit -m
push
完美解決
然後在本地庫 git pull下來
git rebase 解決衝突
解決完後添加進去
git add -u
回退
回退到某個版本
git reset –hard aac3ddf40d2
回退到上個版本
git reset –hard head^