Questions tagged [git-patch]

108 questions
10
votes
2 answers

What is the difference between git cherry-pick and git format-patch | git am?

I sometimes need to cherry-pick a tag with a certain fix into my branch, and used to do so via git cherry-pick tags/myfix This works, but cherry-picking takes an increasingly long time doing "inexact rename detection". My hunch was that this could…
Felix Dombek
  • 13,664
  • 17
  • 79
  • 131
9
votes
2 answers

git pull remote master in detached head

This has been bothering me about git. I have a repository with multiple remotes, and I need to apply hotfixes to the remotes' master branches. So, I try doing: git fetch remote1 master git checkout remote1/master But, I always end up in a…
user2659205
  • 157
  • 1
  • 1
  • 7
8
votes
2 answers

Can I make git add -p show changes like git diff --word-diff?

I have recursively replaced many single word patterns in my code base. Before committing I need to check each for false replacements. It would help me a lot to have git add -p use the format of what --word-diff uses with git diff, where only the…
djangonaut
  • 7,233
  • 5
  • 37
  • 52
8
votes
3 answers

Create Git patches for two files across several renames

I want to move two files from one repository to another. The files were originally added as: /src/init/Price.cs /tests/init/PriceTests.cs The two files were later renamed to: /src/init/PriceValue.cs /tests/init/PriceValueTests.cs And then moved…
Asbjørn Ulsberg
  • 8,721
  • 3
  • 45
  • 61
8
votes
2 answers

Manually editing using git add --patch

So, I've got a file I've been working on in branch A, and I'm just about ready to commit it. However, looking at the diff, I think it's better to put it into two separate commits (Well, in this case, two separate branches, maybe). I've used git…
Jason_L_Bens
  • 374
  • 3
  • 14
6
votes
2 answers

Why does git am leave modified files lying around? How can I adapt my workflow to do better?

This will be a long one but I hope you could bear with me. I am trying to use git to put my team's source code under version control. After trying to find different approaches that would work for me, I finally decided to use git format-patch…
Ghazaly
  • 118
  • 2
  • 8
6
votes
2 answers

how to see the file which would be committed

I have modified a file (or some files) in my directory, and I've used git add to stage some of the changes lines from the file, but not all the changed line. I can use git diff --staged my-file to see the diff of what's changed. git diff --staged…
Jim Newton
  • 594
  • 3
  • 16
6
votes
1 answer

git add -p (interactive patch) and edit mode gives a "corrupt patch at line XX" error

I'm addind my change to a commit with git add -p, now I'd like to use the manual hunk edit mode. I simply have this hunk: # Manual hunk edit mode -- see bottom for a quick guide @@ -46,6 +46,7 @@ function signIn(email, password) { } …
Simon
  • 6,025
  • 7
  • 46
  • 98
6
votes
2 answers

find the first or last commit a patch applies to

Assuming a patch was created from a specific commit in the past, and no longer applies to HEAD. How can I find either the first or better the last commit in the history of HEAD, where this patch applies with "git apply" ? Maybe something with git…
donquixote
  • 4,877
  • 3
  • 31
  • 54
5
votes
1 answer

How do I avoid "error: patch fragment without header at line X" for the following hunk when manually editing hunks in Git?

I am running Git version 2.18.0.windows.1 and trying to manually edit hunks (this is my first time messing with this). I started by splitting a larger hunk and this is the first of the two hunks. I went to edit the first hunk as follows... Old…
12kesselrun
  • 51
  • 1
  • 2
5
votes
3 answers

Git one-liner for applying a patch interactively

I have this patch file, it contains a bunch of modifications that I'd like to apply to a git branch. But I don't want to make one unique commit with all those modifications, instead I'd like to split it into 2 or 3 commits. I know I can achieve this…
arainone
  • 1,928
  • 17
  • 28
5
votes
1 answer

How do I make a git patch from multiple commits at different points in history?

I am trying to create a git patch from multiple commits in my branch. However, I need to create it from arbitrary commits (they wont necessarily be in a range). In between the commits I want to create a patch out of, some of the commits change some…
Andrew
  • 1,355
  • 2
  • 13
  • 28
5
votes
2 answers

Git patch - patch does not apply

I'm trying to split changes into several commits, but I'm facing an issue when manually editing a hunk. Original hunk: @@ -116,8 +116,8 @@ context context - remove 1 - remove 2 - remove 3 + add…
Alex Ferg
  • 801
  • 1
  • 9
  • 17
5
votes
3 answers

How can I generate/apply git patches only for commits that alter specific files

I have two git repos that are forks of each other and I need to occasionally import commits from one to the other. For example: git-repo1 has this directory structure: repo1/project1/src repo1/project2/src while git-repo2 has the following directory…
EMiller
  • 2,792
  • 4
  • 34
  • 55
4
votes
4 answers

Error when trying to apply git diff, "No valid patches in input"

I'm creating a powershell script with the goal of going through several git branches, saving a patch of the working changes, switching to the trunk branch to pull remote commits, then switching back to the working branch and reapplying the working…
Ridiculon
  • 323
  • 4
  • 12