Tag Archives: Git Troubleshooting

fetch origin error: cannot lock ref – Another git process seems to be running in this repository, e.g. an editor opened by ‘git commit’. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier

今日很䌓忙時候 我的Git / Source Tree 出現了以下的錯誤信息
可能是開了太多的ProjectLocal Branch 的關係

Another git process seems to be running in this repository

git -c diff.mnemonicprefix=false -c core.quotepath=false fetch origin
error: cannot lock ref ‘refs/remotes/origin/develop’: Unable to create ‘D:/Git/client-web/.git/refs/remotes/origin/develop.lock’: File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by ‘git commit’. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.”

解決方法十分簡單
我們只需要到這個Project 的 “.Git” 資料夾內
e.g.”/.git/refs/remotes/origin/

或出那個有 “.lock” Extension 的檔案.之後把他”刪除” 便可以了

Hope you find it useful

How to prevent git to commit a file, .gitignore not working

之前的網誌介紹了我把學習 NodeJs的程式碼 Open source了到 GitHub
https://github.com/sharechiwai/NodeExpress
現在發現有小小的難題..
就是很多的Web Application 都有使用第三方的API
如果直接把那些 API KeyCommitGitHub上那便會所有人都能我申請的 API Key
不太安全吧..
所以我便做了很多research看看怎樣解決這個問題.
很多網友都說只要修改 .gitignore 加上那個不想commit的檔案路俓便可以了
.gitignore config
但是試了很久也不成功 在GitHub Application上還是可以看到 那個config.js
config.js still showing on github to be commit

最後終於找到了為什麼 .gitignore not working 和解決方法

加了檔案路徑到.gitignore 都不能解決
是因為.gitignore 只能處理untrack的檔案..
即是如果你的檔案之前 commit過.當那個檔案有任何改變是Git都會說有檔案可以commit

解決方法..
我們需要使用 command prompt 在這個Git的 repository 上輸入以下的指令
git update-index –assume-unchanged [File path / 檔案路徑/ 如果只有指定檔案, 可以加檔案名/ 否則便會整個資料夾都不會 commit]

e.g.

git update-index --assume-unchanged config/config.js

Git command to make git treat the specific file/folder unchanged
得左
config.js not showing on git application

有時候大家想Git再次commit這個檔案..可以在command prompt上使用這個指令
git update-index –no-assume-unchanged [File path / 檔案路徑/ 如果只有指定檔案, 可以加檔案名/ 否則便會整個資料夾都不會 commit]

E.G.

git update-index --no-assume-unchanged config/config.js

Git command to ensure the file/folder are tracked
Hope you find it useful