Git 常用命令筆記
git 在提交之前撤銷add操作
問題:
在使用git時,在未添加.ignore文件前使用 git add . 將所有文件添加到庫中,不小心將一些不需要加入版本庫的文件加到了版本庫中。由于此時還沒有提交所以不存在HEAD版本,不能使用 git reset HEAD命令。
解決:
使用 git rm -r --cached .
ps:注意最后是有點的。
---------------------------------------改寫最后一次提交---------------------------------------
git commit -m'改寫最后一次提交'
git add forgotten_file //補上忘記提交的文件
git commit --amend
----------------------------------------remote--------------------------------------------
git remote add [shortname] [url] //添加遠程倉庫
git remote -v //列出遠程倉庫
git remote show [remote-name] //列出遠程倉庫詳細信息
git remote rename old-name new-name //遠程倉庫重命名
git remote rm [remote-name] //刪除遠程倉庫
----------------------------------------fetch-----------------------------------------------
git fetch [remote-name] //將遠端的數據拉到本地倉庫,并不自動合并到當前分支,仍需手工合并。
---------------------------------------tag-------------------------------------------------------
git tag v1 //建立標簽
git tag -a v1 -m '建立標簽'
git show v1 //查看標簽版本信息
----------------------------------linux 下自動補全功能------------------------------------
在git源碼中 contrib/completion 目錄中的 git -completion.bash 復制到自己的用戶目錄中。并把下面內容添加到你的 .bashrc文件中
source ~/.git-completion.bash
---------------------------------設置Git命令別名---------------------------------------------
git config --global alias.co checkout //設置checkout 命令別名
git config --global alias.br branch //設置branch 命令別名
git config --global alias.ci commit //設置commit 命令別名
git config --global alias.st status //設置status 命令別名
git config --global alias.last 'log -1 HEAD' //查看最后一次提交信息
git config --global alias.visual "!gitk" //啟動gitk。運行外部命令,只需在命令前加上 ! 。
問題:
在使用git時,在未添加.ignore文件前使用 git add . 將所有文件添加到庫中,不小心將一些不需要加入版本庫的文件加到了版本庫中。由于此時還沒有提交所以不存在HEAD版本,不能使用 git reset HEAD命令。
解決:
使用 git rm -r --cached .
ps:注意最后是有點的。
---------------------------------------改寫最后一次提交---------------------------------------
git commit -m'改寫最后一次提交'
git add forgotten_file //補上忘記提交的文件
git commit --amend
----------------------------------------remote--------------------------------------------
git remote add [shortname] [url] //添加遠程倉庫
git remote -v //列出遠程倉庫
git remote show [remote-name] //列出遠程倉庫詳細信息
git remote rename old-name new-name //遠程倉庫重命名
git remote rm [remote-name] //刪除遠程倉庫
----------------------------------------fetch-----------------------------------------------
git fetch [remote-name] //將遠端的數據拉到本地倉庫,并不自動合并到當前分支,仍需手工合并。
---------------------------------------tag-------------------------------------------------------
git tag v1 //建立標簽
git tag -a v1 -m '建立標簽'
git show v1 //查看標簽版本信息
----------------------------------linux 下自動補全功能------------------------------------
在git源碼中 contrib/completion 目錄中的 git -completion.bash 復制到自己的用戶目錄中。并把下面內容添加到你的 .bashrc文件中
source ~/.git-completion.bash
---------------------------------設置Git命令別名---------------------------------------------
git config --global alias.co checkout //設置checkout 命令別名
git config --global alias.br branch //設置branch 命令別名
git config --global alias.ci commit //設置commit 命令別名
git config --global alias.st status //設置status 命令別名
git config --global alias.last 'log -1 HEAD' //查看最后一次提交信息
git config --global alias.visual "!gitk" //啟動gitk。運行外部命令,只需在命令前加上 ! 。
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!