2

So I have a problem adding hunks for my commit properly.

I have something like so:

@@ -6,6 +9,5 @@ #include "incfile.h" bool func3(int&, const char*); -int func1(const int, std::vector<std::unique_ptr<type> >&); -void func2(const std::vector<std::unique_ptr<type> >&); +int func1(const int, std::vector<std::shared_ptr<type> >&); void func4(const int); 

I am trying to only stage only the change to func2 I want t he changes to func1 in a diff commit, and I am struggling because every time and every combination of me removing - or lines or whatever is resulting in a patch that doesn't apply. I thought that I could simply remove the - from in front of func1 and delete the + line for func1 and it would be fine but it is not working.

2 Answers 2

1

Do it like this:

 int func1(const int, std::vector<std::unique_ptr<type> >&); -void func2(const std::vector<std::unique_ptr<type> >&); 

In other words, replace the first - with a (space) and completely delete the last line.

Sign up to request clarification or add additional context in comments.

8 Comments

I have tried that and it still says the patch doesn't apply
Please give the exact error. Also what command do you execute to stage the file?
How exactly are you trying to stage the file?
I'm doing a git add -p file and I have 3 chunks the first one I am not adding this is the second and the third I am not adding.
And you press 'e' at the second chunk? Also, is the third chunk relevant to the second?
|
0

You could try git rebase -i ... to set up a range of commits for mangling. One of the options the -i (interactive) flag gives on each commit is to edit it. That makes the process stop, so you can change the commit at leisure (in this case, editing the modified file to taste), then git add incfile.h to record the change, and git rebase --continue to replay the other commits.

If you are paranoid, you could create a branch off the tip to fool around and don't risk losing it by git checkout -b experiment and work on the new experiment branch.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.