Skip to content

Commit 48c98c8

Browse files
authored
Git Precautions in Linux
1 parent e47679a commit 48c98c8

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,18 @@ git branch -m <name>
538538

539539
![alt tag](https://i.imgur.com/qMjqV3Z.png)
540540

541+
## 使用特定 commit id 建立 branch
542+
543+
有時候我們會想測試某個 commit 的狀態, 這時候可以直接利用 commit id 去建立一個 branch,
544+
545+
方法如下,
546+
547+
```cmd
548+
git checkout -b new_branch <commit id>
549+
```
550+
551+
這樣就會依照你指定的 commit id 去建立出一個 branch.
552+
541553
## 新建分支 branch 並 push
542554

543555
相信大家有時候在 github 上面都會看到,如下圖,很多分支
@@ -1694,6 +1706,50 @@ git remote set-url origin git@blue.github.com:blue-rubiks/t11.git
16941706

16951707
[Git-Flow 基本教學以及概念](https://github.com/twtrubiks/Git-Tutorials/tree/master/Git-Flow)
16961708

1709+
## Linux 注意事項
1710+
1711+
這邊是和大家說一些同時在 windows 以及 linux 底下使用 git 可能會遇到的問題.
1712+
1713+
首先, 在 linux 底下執行以下指令
1714+
1715+
```cmd
1716+
sudo chmod -R 777 folder
1717+
```
1718+
1719+
git 會默認它為改變, 要怎麼把它忽略呢 ? 請執行以下指令 ,
1720+
1721+
```cmd
1722+
git config core.fileMode false
1723+
```
1724+
1725+
也可參考這篇文章 [Git ignore file mode (chmod) changes](https://stackoverflow.com/questions/1580596/how-do-i-make-git-ignore-file-mode-chmod-changes)
1726+
1727+
### 格式化
1728+
1729+
`core.autocrlf`
1730+
1731+
Windows 使用 Enter (Carriage Return 簡寫為 CR) 和 換行(Line Feed 簡寫為 LF) 這兩個字元來定義換行,
1732+
1733+
而 Mac 和 Linux 只使用一個換行 (Line Feed 簡寫為 LF) 字元.
1734+
1735+
所以會導致跨平台協作時出問題.
1736+
1737+
在 windows 上可以這樣設定 ( 代表 LF 會被轉換成 CRLF)
1738+
1739+
```cmd
1740+
git config --global core.autocrlf true
1741+
```
1742+
1743+
Linux 或 Mac 系統
1744+
1745+
```cmd
1746+
git config --global core.autocrlf input
1747+
```
1748+
1749+
以上這樣設定, 會在 Windows 上保留 CRLF,而在 Mac 和 Linux 以及 repo 中保留 LF.
1750+
1751+
如果你想更深入的了解, 可參考 [格式化-core.autocrlf](https://git-scm.com/book/zh-tw/v1/Git-客製化-Git-設定#格式化與空格).
1752+
16971753
## Reference
16981754

16991755
* [13 Git tips for Git's 13th birthday](https://opensource.com/article/18/4/git-tips)

0 commit comments

Comments
 (0)