如何先配置Git仓库再通过git-tfs导入TFS提交至Git?
Absolutely feasible—this is actually the optimal approach to avoid post-import LFS migrations! Setting up your Git LFS configuration upfront ensures large files are tracked correctly from the moment you pull in TFS changesets. Let me walk you through the exact steps to make this work smoothly:
Step 1: Initialize Git Repository & Configure LFS
- Create a new empty folder for your Git repo, then navigate into it via your terminal/command prompt.
- Run
git initto initialize the blank Git repository. - Install Git LFS locally (this sets up the necessary hooks):
git lfs install - Define which file types you want LFS to track (in your case,
.binfiles):
This automatically creates/updates agit lfs track "*.bin".gitattributesfile with the appropriate LFS rules. - Verify the
.gitattributesfile is correct—open it and confirm it contains a line like:*.bin filter=lfs diff=lfs merge=lfs -text - Commit this initial configuration to lock in your LFS setup:
git add .gitattributes git commit -m "Initialize repo with LFS tracking for *.bin files"
Step 2: Set Up git-tfs & Import TFS History
- First, ensure git-tfs is installed (use your package manager or download it from official sources if you haven’t already).
- Set the
MSYS_NO_PATHCONVenvironment variable to prevent path conversion issues (critical for Windows/TFS paths):# For bash/zsh terminals export MSYS_NO_PATHCONV=1 # For PowerShell $env:MSYS_NO_PATHCONV=1 - Initialize git-tfs to connect to your TFS repository. Replace the placeholders with your actual TFS collection URL and branch path:
git tfs init http://tfs:1234/tfs/YourCollectionName $/YourProjectName/PathToYourBranch - Import all TFS changesets into your Git repo:
Git-tfs will convert each TFS changeset into a Git commit, and since your LFS configuration is already in place, any# Fetch all TFS changesets first git tfs fetch # Check out the fetched changes to merge them into your current Git branch git tfs checkout.binfiles will be automatically handled by LFS during this process.
Step 3: Validate the Import
- Confirm large files are tracked by LFS with:
You should see all yourgit lfs ls-files.binfiles listed here. - Check the commit history with
git logto ensure all TFS changesets are preserved as Git commits. - Test cloning the repo to another location to make sure LFS files pull correctly (run
git lfs pullif needed after cloning).
Critical Tips to Avoid Headaches
- Never skip committing the .gitattributes before importing: git-tfs uses your repo’s current configuration during the import, so having LFS set up first guarantees large files are captured by LFS from the start.
- If you need to track additional file types (e.g.,
.zip,.iso), add them withgit lfs track "*.zip"before committing the.gitattributes. - For large TFS repos, speed up the import by processing changesets in batches:
git tfs fetch --batch-size=50
内容的提问来源于stack exchange,提问作者sharpener
相关产品推荐
相关产品推荐

