The projects within the team have dependencies on each other, and due to historical reasons, submodules haven’t been used to manage these project dependencies. Daily development requires manually updating the repository code one by one, otherwise various strange issues may arise.
Referring to online resources, the structure is generally similar. A local manual repository directory (git_list.txt) is maintained, and a script iterates through the directories to perform an update in one go. Before starting each project, this script needs to be executed.
linux
create new file: batch_pull.sh
#!/bin/bash
echo "============ Updating Repository ==================="
# Check if git_list.txt exists
if [ ! -f "git_list.txt" ]; then
echo "git_list.txt file does not exist! Please create and add the Git repository URLs to pull."
exit 1
else
echo "============ Detected Git Repository List File ==================="
fi
# Read each URL from git_list.txt and execute the pull operation
while read -r url; do
if [ -d "$url" ]; then
cd "$url" || continue
git pull
cd ..
echo "Pull $url completed!"
echo "========================================"
else
echo "Directory $url does not exist, skipping pull."
fi
done < "git_list.txt"
Windows
Create a new file: batch_pull.bat
@echo off
chcp 65001 > nul
rem Enter the directory of the script
cd /d "%~dp0"
rem Check if git_list.txt exists
if not exist "git_list.txt" (
echo git_list.txt file does not exist! Please create and add the Git repository URLs you want to pull.
exit /b 1
) else (
echo ============ Detected Git repository list file =========
)
rem Read each URL from git_list.txt and execute the pull operation
for /f %%i in (git_list.txt) do (
if exist "%%i" (
pushd "%%i"
git pull
popd
echo Pull %%i completed!
echo ========================================
) else (
echo Directory %%i does not exist, skipping pull.
)
)
Historical Issues
Also addressed the git
folder permission files encountered after reinstalling the system: Fatal error “unsafe repository (’/home/repon’ is owned by someone else)”.
Most suggested solutions online originate from stack overflow
:
- Add trust to the repository directory:
git config --global --add safe.directory /home/repon
- Manually modify the configuration file
.gitconfig
, specifying the directory to add trust
[safe]
directory = /home/repon
After using this method, repository updates are normal, but there are many warning messages displayed in the console every time git pull
is executed, indicating owner errors.
Desktop System Reinstallation
Machines developed for a long time without system reinstallation, the system partition contained an explosion of garbage files, so I took some time to reinstall the system and encountered this permission issue again. Previous scripts would not run because the permissions were incomplete.
Using the new approach, directly add *
, so that git
automatically trusts all directories.
git config --global --add safe.directory "*"
It is suspected to be a user permission problem, or whether everyone has not adapted to the windows
platform. There are similar chown
commands. You can modify folder ownership. Of course, if your directories are few, manually modifying ownership also works. However, this work computer has added domain information. I don’t know if it’s an abnormal domain deployed by the company or whether there is an anomaly in the local system settings. The user list cannot find the user used for login, and finally processed through command-line operations.
With administrator permissions, execute the powershell
script change_ower.ps1
, remember to adjust the script file encoding to gbk
so that it doesn’t display garbled characters in Chinese operating systems.
# Get the current user's username
$currentUserName = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
# Set PowerShell's character encoding to UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# The root directory path to change ownership
$rootDirectory = "G:\workspace" # Replace with the actual directory path
# Recursively iterate through directories and change file and folder owners
Get-ChildItem -Path $rootDirectory -Recurse | ForEach-Object {
$itemPath = $_.FullName
# Check if it's a file or a folder
if ($_ -is [System.IO.DirectoryInfo]) {
# If it's a folder, use icacls to change the owner permission
$icaclsResult = icacls $itemPath /setowner "$currentUserName" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "Changed the owner of folder $itemPath to $currentUserName"
} else {
Write-Host "Unable to change the owner of folder $itemPath. Error information: $icaclsResult"
}
} else {
# If it's a file, use icacls to change the owner permission
$takeownResult = icacls $itemPath /setowner "$currentUserName" 2>&1
if ($LASTEXITCODE -eq 0) {
# Write-Host "Changed the owner of file $itemPath to $currentUserName"
} else {
Write-Host "Unable to change the owner of file $itemPath. Error information: $takeownResult"
}
}
}
Unexpected situations still occurred, and the Chinese information output by the script was garbled. I tried setting the console character encoding and adjusting the script encoding, but the output was all garbled. It is likely that my brain wasn’t clear at all. I tried enabling the beta feature in Control Panel - Region - Language Settings to globally enable Unicode encoding, and the script executed normally. Several development software programs could not work properly. Later, when reviewing materials, I remembered to adjust the script file encoding to gbk
.