執行git stash
保存後,git status
將顯示無任何改動。html
git stash # Temporarily stores all modified tracked files git stash list # Lists all stashed changesets git stash pop <stash> # Restores the stashed files, and delete the stashed files. git stash apply <stash> # Restores the stashed files, and reserve the stashed files. git stash drop # Discards the most recently stashed changeset git stash show # Show the latest changes recorded in the stash as a diff between the stashed state and its original parent. git stash clear # Remove all the stashed states.
不一樣的人修改同個文件的同一個地方,而後推送到遠程庫是會發生「推送失敗」,由於推送有衝突。
解決方法:先用git pull
抓取最新的提交,而後在本地合併,解決衝突,再推送。
使用git pull
前,必須指定本地branch分支與遠程origin/branch分支的連接(git branch --set-upstream-to
)git
嘗試用git push origin <branch name>
推送修改。
若是推送失敗,可能由於遠程分支比本地更新早,使用git pull
試圖合併。
若是合併有衝突,則須要解決衝突,並在本地提交,再用git push origin <branch name>
推送。windows
Local配置優先級高於global配置,並且Local的配置必須在local repository目錄下完成。
示例:安全
$ git config --local user.name "anliven" # 配置local repository的用戶名 $ git config --local user.email "anliven@yeah.net" # 配置local repository的郵箱 $ git config --local --list # 顯示local repository配置信息 $ git config --local --unset [value-regex] # 去除local repository配置 $ git config --local --edit # 交互式local repository配置
Git配置文件優先級:local > global > system
bash
配置文件 | 有效範圍 | 查看 | 配置方法 | 名稱及目錄 |
---|---|---|---|---|
local | 本地倉庫 | git config --local --list | git config --local --edit | 本地倉庫目錄下,例如:<local repository>\.git\config |
global | 全部倉庫 | git config --global --list | git config --global --edit | 用戶目錄下,例如:C:\Users\xxx.gitconfig |
system | 不建議改動 | git config --system --list | git config --system --edit | git的安裝目錄下,例如:C:\Program Files\Git\mingw64\etc\gitconfig |
利用git rebase -i
把其它commits標註爲squash,從而將其它commits併入一個commit。
合併多個 Commit
合併 commit 保持分支幹淨整潔app
link
git pull = git fetch + git merge
git pull --rebase = git fetch + git rebase
fetch
# 在相應Repository目錄中查看文件權限 git ls-tree HEAD # 修改權限(權限修改後,至關於文件進入了index) git update-index --chmod=+x <test.sh> # 提交修改 git commit -m "script permission update" # 確認修改結果 git ls-tree HEAD
^M: bad interpreter
檢查文件格式,必要時使用dos2unix命令轉換文件格式。
在windows git下,建議關閉自動換行,並啓用安全換行檢查。ui
# 關閉自動換行的設置 git config --global core.autocrlf false # 啓用安全換行符檢查 git config --global core.safecrlf true
默認狀況下,git將忽略空文件夾,也就是說空文件夾沒法加入到repository。
解決辦法:在空文件夾下建立包含!.gitignore
內容的.gitignore
文件便可。.net