git常规命令大全
git remote show origin 顯示遠端信息
git push --mirror +遷移的服務器路徑(ssh)
git remote add origin +ssh 地址
git push -u origin 分支名
git push origin :分支名 刪除遠程分支
git push origin --delete 刪除遠程分支
1)配置使用git倉庫的人員姓名?
git config --global user.name “Your Name Comes Here”
2)配置使用git倉庫的人員email?
git config --global user.email “you@yourdomain.example.com”
前者是git 工具
git remote set-url origin +ssh地址 git遷移
ssh-keygen -C ‘986323930@qq.com’ -t rsa //生成此郵箱公鑰
git rm +文件名(失敗,可以執行git add+文件名操作)
git commit -m “刪除文件件/文件名”
在push到服務器上去
git revert 是生成一個新的提交來撤銷某次提交,此次提交之前的commit都會被保留
git reset 是回到某次提交,提交及之前的
git add 增加所有
git rm -f 文件名/ //不保留本地,刪除文件
git rm -r --cached +文件名 刪除文件(并保留本地)
git clone xxx.git “指定目錄”
git reset --hard 工作區改變 暫存區改變,版本庫改變(–hard還原了暫存區和工作區的文件到某個具體的commit,(即已提交的,暫存區和工作區文件全部還原到指定的commit) 并移動HEAD指針到指定commit
)
git reset --mixed 工作區不變,暫存區改變 版本庫改變(–mixed是默認操作,會把已經提交的和暫存區的文件退回到工作區,并移動HEAD指針到指定commit)
git reset --soft 工作不變 暫存區不變, 版本改變( --soft會把已經提交的文件退回到暫存區,暫存區和工作區原有的文件不變,并移動指針到指定commit,并不還原任何文件
)
在本地新建同名的(“dev”)分支,并切換到該分支)
–keep會把已經提交的文件重置到commit ID的狀態,暫存區的退回到工作區,并移動指針到指定commit
git checkout -t origin/dev 該命令等同于:
git checkout -b dev origin/dev
git clean -f //強制刪除當前目錄下不干凈的東西
git branch -r 查看遠程分支
git branch (-m | -M) [] 重命名分支
git branch -d -r origin/遠程分支名
git checkout +文件名 撤銷當前改動
git commit -m “信息"文件名 //對單個文件的提交
git commit -am"信息” 對所有文件的提交
git branch --merged # 顯示所有已合并到當前分支的分支
git branch --no-merged # 顯示所有未合并到當前分支的分支
git log --decorate --graph --oneline --all 查看所有分支歷史
git push origin --tags //把本地tag推送到遠端
git log --oneline --decorate --graph --all
git tag “v0” a1aba30
– 第三個參數是tag名稱,第四個參數是commit的hash值,可用第一個命令查看
git config --global alias.lol “log --oneline --decorate --graph --all”
--起別名 此時命令為git lol
git stash save -a “暫存區別名”
--git add之后但沒有commit,想切換分支就必須將工作區中的內容備份stash save保存進git棧內
git stash list
--查看當前分支下,git棧的所有備份,可以利用這個列表決定從哪個地方進行恢復
git stash pop --index stash@{0}
--從git棧中讀取最近的一次內容,恢復工作區的內容
git stash drop stash@{0}
--清理git棧內的指定備份,如果最后一個參數為空,則默認清理最后一個備份
git stash clear
--清理git棧內所有的備份
git abort --abort
--放棄此次merge操作
git clean - n //查看將要刪除那些文件
git clean -f //刪除所有不是被忽略的文件
git clean -f 文件名 //刪除此文件
git tag -a tag號 -m “信息” 提交id
git cherry-pick 提交id//挑選某一次提交
git log --color --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset’ --abbrev-commit
git log --oneline --decorate --graph --all
git log --color --graph --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset’ --abbrev-commit -1 HEAD
git revert 增加reflog信息
gir reset 會增加reflog信息,會撤銷提交信息
git reset --mixed 從版本庫中撤回,而且暫存區也撤銷,導致未跟蹤
git revert 44ec5b6 -m 1 1代表的是分支 撤銷合并點的時候
reset和revert區別:
reset是回朔到指定的commit版本(指定commit版本之后的操作都消失了)。(不會改變想對應的遠程分支,push上時,需要強制推送)
revert是刪除指定的commit操作的內容(指定的版本內容消失,之前和之后commit版本內的操作都保留),
但是這個操作也會做了一個新的commit提交版本。(會改變想對應的遠程分支,push上時,不要強制推送)
(revert如果需要反轉多個,必須從最后的開始反轉, 加 -n可以不馬上提交,之后一起提交。git revert -n HEAD)
git push -f origin 分支名
git merge 被合并分組名 --no-ff -m “信息”
git branch -vv 本地分支加遠程分支
git ls-files -s //查看暫存區內容
git ls-tree -s //查看樹內容
/配置git界面顯示******
git config color.ui true 比較高亮
git config --global color.ui true
git config --global color.diff.old red blod
git config --global color.diff.new green blod
git config --global color.diff.meta yellow blod
git config --global color.diff.frag magenta blod
git config color.status.added yellow
git config color.status.changed green
git config color.status.untracked cyan
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global i18n.commitEncoding UTF-8 //提交顯示亂碼
git config --global i18n.logOutputEncoding UTF-8 //顯示日志亂碼
git config --global alias.lg “log --color --graph --pretty=format:’%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset’ --abbrev-commit”
配置BeComp
git config --global merge.tool bc
git config --global mergetool.bc.path “D:\Beyond Compare 3”
/配置git界面顯示******
git diff 兩個版本的哈希值 --name-only顯示比對文件
git diff 顯示工作區和暫存區的差異
git diff HEAD,顯示工作區和HEAD之間的差異
git diff --cached,顯示暫存區和HEAD之間的差異
git archive -o 包名.zip HEAD
git diff --name-only 只顯示 工作與暫存區 別修改 的文件名(未加入暫存區中)
git diff --name–status 只顯示 工作與暫存區 別修改 的文件名 和狀態(未加入暫存區中)
git config user.email 查看設置的郵箱
git config user.name 查看設置的用戶名
git diff //當前工作區與暫存區比較
git diff HEAD //當前工作區也版本庫比較
git diff --cached //暫存區與版本庫比較
git clone -b “分支名” url 項目取名
git status --ignored //查看所有被忽略文件的狀態
二 查看與對比歷史記錄
主要學習以下幾條命令命令 1.git log 2.git show 3.git diff
git log
--顯示完整commit信息,若一頁顯示不全,按空格或f向下翻頁,按b向上翻頁,按q退出
git log -p
--顯示每一次commit之間差異信息
git log --stat
--顯示每一次commit之間差異的統計信息
git log --oneline --decorate --graph --all
--顯示完整的歷史示意圖,–oneline顯示單行信息,–decorate顯示引用信息,–graph顯示圖形化歷史信息 --all顯示所有分支信息
git show <commit的對應hash值>
--查看當前分支下的提交
git show master^
--master當前指向的提交記錄的第一父提交
git show master^2
--master當前指向的提交記錄的第二父提交
git show --stat master^2
--顯示提交所做出的改變信息
git diff
--顯示工作區和暫存區之間的差異
git diff --cached
--顯示暫存區和歷史提交之間的差異
git diff HEAD~2 – master.txt
--顯示當前工作區與指定歷史提交之間的差異,后面可以指定某個特定文件名
git diff --cached HEAD~2 – master.txt
--顯示暫存區與指定歷史提交之間的差異,后面可以指定某個特定文件名
git diff HEAD HEAD~2 – master.txt
--顯示兩次歷史提交之間的差異,后面可以指定某個特定文件名
git diff --color-words / git diff --word-diff
--顯示工作區與暫存區之間文件中,具體單詞之間差異
git status --untracked-files=no 查看非跟蹤文件的狀態
三 撤銷修改
主要學習以下幾條命令: 1.git checkout 2.git reset 3.git clean 4.git revert
git checkout – master.txt
--撤銷工作區中master.txt的修改,其實是將暫存區中的文件覆蓋了工作中的文件
git reset master.txt
--撤銷git add后的文件回工作區
git checkout <某次歷史提交> – <指定文件名>
--回退當前工作區中的某個文件的歷史版本
git reset <某次歷史提交> – <指定文件名>
--回退暫存區中的某個文件的歷史版本
vim .gitingore
git add .gitingore
git commit -m “add ingore”
--可以在.gitingore中增加一些需要忽略的文件,此時git add .的時候就不會對.gitingore中忽略的文件進行add
git clean -n/-f/-df
--git clean主要是刪除一些沒有git add的文件,-n是顯示將要刪除的文件和目錄, -f刪除文件,-df刪除文件和目錄
git clean -n -X/git clean -X -f
--顯示并刪除將要刪除的.gitingore中忽略的文件
git revert <某次歷史提交>
--創建一個commit來覆蓋當前的commit,HEAD指針是向后移動的,而
三 重寫歷史記錄
主要學習以下幾種命令: 1.git commit --amend 2.git rebase 3.git reset 4.git reflog
git commit --amend
--修改已經提交的commit -m后所帶的信息
git checkout -b test_rebase HEAD~
--基于當前分支的上一個提交創建分支test_rebase
git rebase master
--合并master分支,但也git merge的區別就是,合并操作后,當前分支的歷史看上去是線性的,而git merge后,當前分支有兩條路徑。處理流程如下:
--git rebase master
--處理沖突
--git add <沖突文件>
--git rebase --continue
git rebase --abort
--取消此次rebase的操作
git reflog -10
--維護HEAD引用的變化歷史,顯示近10條的記錄
git reset --hard/–mixed/–soft HEAD@{5}
--hard還原了暫存區和工作區的文件到某個具體的commit, 并移動HEAD指針到指定commit
--mixed是默認操作,只還原了暫存區,并移動HEAD指針到指定commit
--soft只是移動HEAD指針到指定commit,并不還原任何文件
總結
- 上一篇: const 一级指针的启示
- 下一篇: 蓝桥杯vip答案java_Java实现