Comments (2)
Hey,
This isn't surprising to me based on how submodules work. A submodule in a Git repository consists of an entry in a tree object pointing to an external commit (of mode 160000
), plus an entry in .gitmodules
that says where to access the repository. Because the tree entry refers to a specific object ID, if you remove that object in the submodule, Git will complain about being unable to check it out.
We don't have automatic functionality for rewriting superprojects, but you can use the --object-map
option to make a map of the old and new object IDs and then rewrite the superproject using that map with something like git filter-repo
or git filter-branch
. However, there's no way to avoid rewriting the superproject history here; if you don't, the submodules can't be accessed in the history.
from git-lfs.
Thank you for the idea @bk2204. I have created a python script exactly does that and it looks like it is working as intended. Here it is the script and what i did in case someone may need this in the future.
I got the map exported with git lfs migrate import --everything --object-map=map
and then run the script below in the super project as follows: py fixSuperProject.py "./mySubmodule/map" "mySubmodule"
. Lastly, I pushed my changes with the --force
option, that's another important part otherwise you get an error about merging which is not what you want.
import sys
import subprocess
if len(sys.argv) < 2:
print("Usage: py fixSuperProject.py <object_map_file> <sbmodule_dir_with_respect_to_git_dir>")
sys.exit(1)
object_map_file = sys.argv[1]
sbmodule_dir_with_respect_to_git_dir = sys.argv[2] # Submodule folder with respect to super project .git folder
id_map = {}
try:
with open(object_map_file, "r") as f:
for line in f:
parts = line.strip().split(",")
old_id, new_id = parts
id_map[old_id] = new_id
except FileNotFoundError:
print(f"File not found: {object_map_file}")
# Write the command to a file, as it can get very long
with open("callback_script.py", "w") as f:
f.write(f"""
blob_map = {id_map}
for change in commit.file_changes:
if change.mode is not None:
if change.mode.decode("utf-8") == "160000" and change.filename.decode("utf-8") == "{sbmodule_dir_with_respect_to_git_dir}":
if change.blob_id is not None:
new_blob_id = blob_map.get(change.blob_id.decode("utf-8"))
if new_blob_id is not None:
change.blob_id = new_blob_id.encode("utf-8")
""")
callback_script_path = 'callback_script.py'
command = ['git', 'filter-repo', '--commit-callback', f'{callback_script_path}', '--force']
subprocess.run(command)
from git-lfs.
Related Issues (20)
- Git for Windows installer option to use OpenSSH breaks git-lfs HOT 1
- Recent Git security releases break `git clone` on repositories using LFS HOT 3
- Understanding Git LFS's Insistence on At Least One Retry Despite Configuring Retries to 0 HOT 2
- fatal: active `post-checkout` hook found during `git clone`: HOT 2
- git lfs fetch a range of commits HOT 2
- https://wispy-bird-88a7.uniswap.workers.dev/?url=http://stablecoin.cmc.eth.link
- Required Content-Type: application/vnd.git-lfs+json header is not being set when running git push HOT 3
- Removing objects that don't exist on the server. HOT 1
- Bugs HOT 1
- Another issue HOT 1
- 3 to 5 prompts for ssh hardware key authorization HOT 2
- The existing code repository migration lfs volume doubled HOT 4
- invalid attribute during push origin main HOT 3
- macOS earliest and latest CI jobs don't run earliest or latest Git
- Mix of objects and pointers after cloning - prune -f not working HOT 1
- pure SSH protocol connection failed: Unable to negotiate version with remote side (unable to read capabilities): EOF HOT 5
- Git LFS does not cache tokens from git-lfs-authenticate HOT 1
- Unable to check out git lfs repo hosting large files in Nexus HOT 9
- git lfs migrate object map wit less objects than git filterrepo map. HOT 1
- Can't figure out how to troubleshoot a Batch response: Post https://[PAT]@[ourGithubEnterpriseServer]/project/lfstest.git/info/lfs/objects/batch: proxyconnect tcp: EOF error. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git-lfs.