# Git

<https://github.com/orefalo/g2>

<https://blog.yorkxin.org/2011/07/29/git-rebase>

新手學習指令列Git的網站 <https://learngitbranching.js.org/index.html>

4-4完成

移動分支位置 git branch -f 'branchName' 'commitHash'

嫁接分支 git rebase 'branchName'

嫁接分支 先切到要被接的分支 git cherry-pick 'commitHash'

嫁接分支 + 修改commit順序 git rebase -i 'branchName'

錨點 git tag 'tagName' 'commitHash'

repository 版本庫

commit checkout reset 基本功用

branch merge 下一步

clone pull push fetch 遠端合作

## 如何取消 Commit

假設當前在 master 這個分支上 剛剛多做了 "1" 個錯誤的commit

可以利用

```
git reset master^
```

`^` 的數量，就是想回到幾個以前的commit

如果數量太多 想回到五個以前，則這樣打就好

```
git reset master~5
```

其實reset 還有分三種模式

mixed (default) 丟回工作目錄 soft 丟回暫存區 (沒用過) hard 直接丟掉 (沒用過)

## Git for windows 中文亂碼問題

參考資料:(<https://blog.miniasp.com/post/2017/09/17/Git-for-Windows-Command-Prompt-Display-Chinese-Issues>)

在系統的環境變數 新增一個變數 `LC_ALL` 值為 `C.UTF8`

## pull remote branch

參考資料:(<https://stackoverflow.com/questions/9537392/git-fetch-remote-branch>)

git version: 1.7.2.3 & 更高版本

`git checkout <branch_name>`

`git checkout release`

## git remote Authentication Failed

參考資料:(<http://kentlogger.blogspot.com/2017/04/clonegitlabauthentication-failed.html>)

控制台 > 使用者帳戶 > 管理 Windows 認證 > 將 **一般認證** 的地方，該 domain 的認證都刪掉

之後執行 pull / push 時，重新打一次帳密就OK了

## Git Tag

參考資料:(<https://devconnected.com/how-to-delete-local-and-remote-tags-on-git/>)

```
#列出 Tag 的清單
git tag -l

#刪除指定的 Tag
git tag -d <tag_name>

#刪除遠程Git Tag  (較不推薦)
git push --delete origin <tag_name>

#刪除遠程Git Tag (推薦)(指定參考)
git push origin :refs/tags/<tag_name>

有些情況分支名稱會和標籤名稱相同，這時候就要清楚指定到底是哪一個
```
