Troubleshooting
Why Git Commits Fail on an HMI Project Lock File
Short answer
Git fails with permission denied on TcHmiSrv.lock inside the .engineering_servers/ project directory because the open HMI solution or the running engineering server holds the lock file. Close the HMI solution, add .engineering_servers/ to .gitignore, and if Git already tracks the directory, run git rm --cached -r on it before committing.
On this page
The commit fails because the TwinCAT HMI engineering solution or its engineering server still holds TcHmiSrv.lock open, not because Git dislikes lock files. Close HMI.sln, add .engineering_servers/ to .gitignore, and if Git already tracks that directory, remove it from the index with git rm --cached -r .engineering_servers/ before committing. Everything below assumes a TwinCAT 3 / TE2000 HMI project under Git source control in Visual Studio.
Read what the error is actually telling you #
The reported failure names both the operation and the exact file:
error: open(".engineering_servers/TestLabHMI/TcHmiSrv.lock"): Permission denied
fatal: Unable to process path .engineering_servers/TestLabHMI/TcHmiSrv.lock
Git must read every working-tree file it stages. The error is an operating-system denial on opening a local file, so the failure happens before Git talks to any remote. That gives you a clean diagnostic branch: if a later push fails, that is a separate remote problem and does not explain this error. The .lock extension itself imposes no Git restriction; Git can version files with that extension whenever it can read them.
The useful signal is the directory. .engineering_servers/ is generated engineering-server content, and TcHmiSrv.lock inside it belongs outside version control. Deciding that removes the file from Git's workload entirely, which is better than fighting the access denial.
Test whether the open solution is the cause #
Do this in order and read the result before touching permissions:
- Save the HMI project changes and close
HMI.sln. - Retry the exact operation that produced the fatal error.
- If it succeeds, an active engineering process was obstructing access; continue to the ignore-rule step so it cannot recur.
- If the same error remains, use the operating system's process and file-handle inspection to find which process owns the file, stop that process through its normal controls, and retry.
- Only if no active owner explains the failure, inspect the file and parent-directory access permissions.
Keep the two checks separate: closing the solution tests active file use, while permission inspection tests filesystem authorization. Running Git elevated is not a substitute for the decision in the next section, and deleting a lock file while its owner is still running fixes nothing.
Decide which HMI files stay out of the repository #
The vendor's own position is that a new HMI project created with Git source control writes a generated .gitignore into the project folder. The patterns it supplies are:
.engineering_servers/
liveview_*
*.cache
*.db-shm
*.db-wal
*.pid
.hmiframework/
.hmipkgs/*-*-*-*/
tchmipublish.journal.json
| Pattern | Scope | Note |
|---|---|---|
.engineering_servers/ |
Engineering-server directory content | Covers TcHmiSrv.lock at the reported location |
liveview_* |
Names with that prefix | Generated live-view files |
*.cache, *.db-shm, *.db-wal, *.pid |
Cache, database companion and process files | Review broad suffix rules in multi-project repositories |
.hmiframework/ |
Framework directory | Generated framework content |
.hmipkgs/*-*-*-*/ |
Selected package subdirectories | Keep the selective pattern; do not exclude the whole package directory |
tchmipublish.journal.json |
Publishing journal | Do not extend the rule to other JSON project files |
Spell the directory with an underscore: .engineering_servers/. An entry with a hyphen will not match the reported path, and the ignore rule then silently does nothing. Skip a blanket *.lock rule unless every matching file in scope is intentionally disposable, because other tools use lock files as deliberate project inputs. TwinCAT's source-control documentation describes how the engineering environment integrates with Visual Studio source control, so review the project-specific ignore file before adding duplicate rules of your own.
Fix the repository when the directory is already tracked #
An ignore rule controls discovery of untracked files only. It does not retroactively remove entries from Git's index, which is why an apparently correct .gitignore can coexist with the same fatal error. Check your tracked-file listing for anything under .engineering_servers/:
- Nothing tracked: add the rule, save
.gitignore, and retry staging your intended changes. - Directory tracked: add the rule, then remove the directory from the index without deleting the working files:
git rm --cached -r .engineering_servers/
- Only the lock file tracked: remove just that entry:
git rm --cached .engineering_servers/TestLabHMI/TcHmiSrv.lock
The --cached option removes index entries while leaving the files on disk, so the running engineering server keeps working. If Git refuses the removal because staged content differs, inspect those differences first; do not force the removal.
As a worked example, on a repository where HMI.sln is closed, the rule is added, and git status shows three files under .engineering_servers/TestLabHMI/ plus your edited HMI.sln: the git rm --cached -r .engineering_servers/ command stages three deletions and leaves the files on disk, the .gitignore edit is staged alongside, and git commit -m "Remove and ignore .engineering_servers/ content" records exactly those four changes. Retry the commit that failed; it now completes because Git never opens the lock file.
Confirm the fix holds #
Reopen the HMI solution, edit a screen, and commit with the solution open. The commit should succeed because the lock file is no longer part of the repository. If it fails again, the ignore pattern does not match the path as spelled in your repository — check the underscore and the leading dot first. A later failure on git push is a remote-side problem and starts a different diagnosis.
This failure sits on the authoring side. When the opposite symptom appears — missing files after someone clones the repository to a new workstation — the causes and fixes differ, and the article on fixing an HMI project that fails after a Git clone covers that case. If the same repository also misbehaves when publishing after a package update, the article on TwinCAT HMI publish failures after a NuGet update is the closer match. For permission-denied errors on a web directory rather than a lock file, the page on resolving a LogicLab web directory permission denied works the same diagnostic branch: identify the owning process before changing permissions.
Questions asked
Is a .lock file always a problem for Git?
No. Git versions any file it can read, whatever the extension. The failure here is that another process holds TcHmiSrv.lock open with sharing restrictions that block the read, so Git reports the operating system's permission error. A lock file that exists while its application is closed commits normally.
Why doesn't my .gitignore rule fix the error?
An ignore rule only affects files Git has not yet tracked. If the engineering-server directory was committed before the rule was added, its entries stay in the index and Git still reads them at every commit. Remove the directory from the index with git rm --cached -r .engineering_servers/ while the files stay on disk.
Can I just echo a *.lock rule into .gitignore?
Avoid it. Other tools use lock files as deliberate project inputs, and a blanket *.lock rule ignores every such file in its scope. Ignore the parent directory .engineering_servers/ instead: it targets the generated engineering-server subsystem and covers the lock file at its documented location.
The HMI solution is closed but the error remains. What then?
An engineering-server process may still hold the file. Use the operating system's process and file-handle inspection to find the owning process, stop it through its normal controls, and retry. If no process explains it, check the file and parent-directory access permissions before changing anything else.
Where do I get the ignore list for a TwinCAT HMI project?
Create the HMI project with Git source control selected, and the project template writes a .gitignore into the project folder containing the generated-content patterns, including .engineering_servers/. Review that file before adding duplicate rules, and keep its exact spellings, such as the underscore in .engineering_servers/.