I am trying to apply a series of patches from 1 git repository to another git repository using git am -3 \"path to a patch\". I apply them in order, from patch 1-4, it works
I have gotten similar conflicts, and an nth solution that worked for me was to:
new_repo> git am -3 /tmp/bunchopatches/*
# 10: ERROR happens
new_repo> git am --show-current-path | head -n 1
# From fe89d2a53ccf30d068fdd5596a325f06b74ec4af Mon Sep 17 00:00:00 2001
orig_repo> git checkout fe89d2a53ccf30d068fdd5596a325f06b74ec4af^
orig_repo> cp aff/ected/files/* /new_repo/aff/ected/files/
new_repo> git add aff/ected/files/*
new_repo> git am --continue
# rince and repeat (goto 10)
(If you do the orig_repo> commands in a separate window this can actually be a rather quick process, just applied 80 patches with about 10 spacing conflicts this way=
Are you using submodules in your project?
There was a bug in git 1.7.12 to 1.8.1.2 where an updated submodule would cause a rebase (or patch) to fail with the error message:
fatal: sha1 information is lacking or useless
leaving the commit empty if applied.
More info here.
Updating git to version 1.8.4 solves this problem
I had this when trying to apply patches from one repository into one which had unrelated history (the same project but with rebuilt git history). The reason you get the message fatal: sha1 information is lacking or useless (dev/afile.c)
is that when git is trying to do a 3 way merge it needs to access the state of that file. Those files are pointed to by the hashes in the format patch output (e.g.)
diff --git a/dev/afile.c b/dev/afile.c
index ebbd50fc0b7..ef1ca87ead0 100644
--- a/dev/afile.c
+++ b/dev/afile.c
ebbd50fc0b7 and ef1ca87ead0 refer to hashes of the content of the files, not commit hashes.
If you try:
git cat-file blob <hash from patch>
Git will report:
fatal: Not a valid object name <hash from patch>
Git can't find them because those versions of the file are not available in your local repository (hence the message Repository lacks necessary blobs to fall back on 3-way merge.
). You can make those objects available in your local repository with:
git remote add old_repo <url>
git fetch old_repo
Now, when you run:
git cat-file blob <hash from patch>
You should be given the contents of that file. Now try your git am
command again and it should be able to do 3 way merges.
The patch file starting with 0001-
cannot be applied cleanly - there is some conflict.
Git wanted to resolve that conflict by looking at commits this patch has been based on, but you don't have those commits in your repository.
Probably the patch has been created from a branch that had commits that were never shared, or either your or submitter's branch has been rebased.
It doesn't matter that patch 0005-
can be applied with no error. The error is about 0001-
specifically.
Just did the following and was able to solve this issue:
patch -p1 < example.patch
I ran into this issue when I tried to create the patch while on the wrong branch.
I thought "git format-patch ..." would be able to determine what I wanted because you can specify the main branch and the branch you want to patch in the format-patch call. I realized it was wrong because it was mentioning commits that were part of a branch that didn't exist on the site I was patching to.
Long story short, make sure you are on the branch you want to patch when you create the patch.