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。運行外部命令,只需在命令前加上 ! 。