添加文件
git add file.txt
git commit -m "add file.txt"
撤銷(xiāo)工作區(qū)的修改
git checkout --file
撤銷(xiāo)暫存區(qū)的修改
git reset HEAD file
回退到當(dāng)前版本
git reset --hard HEAD
回退到上一個(gè)版本
git reset --hard HEAD^
刪除版本庫(kù)中的文件
git rm file
---------- 現(xiàn)有本地庫(kù)畸冲,再創(chuàng)建遠(yuǎn)程庫(kù)
添加遠(yuǎn)程倉(cāng)庫(kù)
git remote add origin git@github.com:michaelliao/learngit.git
提交到遠(yuǎn)程倉(cāng)庫(kù)的master分支
git push origin master
創(chuàng)建分支并切換到分支
git checkout -b xxx
切換到分支
git checkout xxx
在a分支上合并b分支的修改
git checkout a
git merge b
刪除分支
git branch -d xxx
強(qiáng)制刪除分支
git branch -D xxx
暫存工作區(qū)的修改
git stash
查看暫存的工作區(qū)修改
git stash list
取回暫存的工作區(qū)修改
git stash pop
在本地創(chuàng)建和遠(yuǎn)程分支對(duì)應(yīng)的分支
git checkout -b branch-name origin/branch-name
建立本地分支和遠(yuǎn)程分支的關(guān)聯(lián)
git branch --set-upstream branch-name origin/branch-name
從遠(yuǎn)程抓取分支
git pull
創(chuàng)建標(biāo)簽
git tag xxx
查看標(biāo)簽
git tag
對(duì)某次的提交(commit)打標(biāo)簽
git tag xxx xx_commit_id
刪除本地標(biāo)簽
git tag -d xxx
刪除遠(yuǎn)程標(biāo)簽
git push origin :refs/tags/<tagname>
推送標(biāo)簽到遠(yuǎn)程
git push origin <tagname>
推送全部的標(biāo)簽到遠(yuǎn)程
git push origin --tags
推送本地分支到遠(yuǎn)程
git push origin local_branch:remote_branch
git修改分支名稱(chēng)
git branch -m old_branch new_branch // Rename branch locally
git push origin :old_branch // Delete the old branch
git push --set-upstream origin new_branch // Push the new branch, set local branch to track the new remote