當 git push 執行結束後沒有上傳任何記錄,git log 查找不到 commit 記錄。
一定要 commit !
-
使用 git reflog 可以查找到所有提交記錄
f823529 HEAD@{0}: pull origin Algorithms: Merge made by the 'recursive' strategy. 8f72b1f HEAD@{1}: merge lostFound: Fast-forward 8be1430 HEAD@{2}: checkout: moving from lostFound to Algorithms
-
然後,reset Head:
git reset --hard 8be1430
- 新建分支 LostFound,並提交
git branch LostFound
git add --all
git commit -m "Push lost files"
git push origin LostFound
- 切換到原分支,合併代碼:
git checkout LocalBranch
git merge LostFound LocalBranch
git push origin LocalBranch
-
在git 庫中查看丟失的文件就找回了。之後清理分支代碼就好了。
-
當因網絡原因,CI 或 IDE 集成的 git 自動提交失敗,本地會生成一個臨時的 branch,不容易發現。
當 checkout 到另一個分支,則會提示該臨時分支名稱,一般是類似於 head 名稱的數字串,這時記住該分支名稱,回到本地工作分支,然後將這個臨時分支 merge 過來即可。
Github Flow:
Create Branch -> Add commits -> Open a pull request -> Discuss and review code -> Deploy -> Merge (to master)
參考:Understanding the GitHub flow
Git 中文亂碼
如 git status 中文名稱被轉爲了 8 進制字符串
-
Git 的配置如下:
git config --global core.quotepath false # 顯示 status 編碼
git config --global gui.encoding utf-8 # 圖形界面編碼
git config --global i18n.commit.encoding utf-8 # 提交信息編碼
git config --global i18n.logoutputencoding utf-8 # 輸出 log 編碼
export LESSCHARSET=utf-8 # 最後一條命令是因爲 git log 默認使用 less 分頁,所以需要 bash 對 less 命令進行 utf-8 編碼
github https 免手動登錄
-
Personal access token
-
在鏈接中指明username ,passwd
參考:git clone https://username:[email protected]
git clone https://banrieen:[email protected]/nginx/nginx.git