코드 파일을 여러 번 변경 했으므로 diff를 검사하기 전에 git add -p path/to/file.hpp
을 검사하십시오.git add -p에서 덩어리를 편집 할 때 "패치 적용되지 않음"수정 -p
변경 사항 요약 : 일반 클래스 선언을 템플릿 클래스 정의로 변환했습니다. 그렇게함으로써 파일의 맨 아래에서 많은 양의 코드를 가져 와서 맨 위로 옮겼습니다. (이제는 클래스 앞에 정의해야하는 예외 클래스입니다.) 그런 다음 하나의 클래스를 대체했습니다. - 몇 줄의 코드를 가진 라이너 (메소드 선언) (메소드 구현).
힘내 나의 변화의 문맥을 정확하게 감지 할 수 없었고, 근본적으로 서로를 가로 질러 두 줄 사이에 전혀 연결이 없었던 큰 벌레에 줄을 추가하고 추가했다. diff. 변경 사항을 나중에 쉽게 검사 할 수 있도록 여러 변경 사항을 컨텍스트에서 가져 오려고했지만 추가 된 모든 행과 삭제 된 행을 동일한 순서로 유지하고 추가 된 행 수 및 변경되지 않은 행을 유지하는 데주의를 기울였습니다. . 나는이 완료되었을 때
, 나는 오류 메시지error: patch failed: include/aof/physics/magnetic-field.hpp:143
error: include/aof/physics/magnetic-field.hpp: patch does not apply
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?
확인을 가지고, 그래서 어디 선가 실수를했다. 좋아요, 다시 시도 할게요. 다시 같은 메시지.
내가 y
으로 대답하면 편집 한 패치로 돌아갈 수는 있지만, 그게 나에게 무슨 문제가 있는지 알지 못해서 그다지 도움이되지 않습니다. 패치를 불행히도 편집하지 않으려 고 노력한 후에는 여기서 더 나은 오류 메시지를 얻을 수있는 방법이 있습니까? 어떻게 을 찾을 수 있습니까? 패치가 적용되지 않아서 고칠 수 있습니까? 내가
원래 패치를 달성하기 위해 노력하고있어 명확히하기 위해
간단한 예. 여기에 무슨 일이 일어나고 있는지보기가 쉽지 않습니다 ...
- ClassConstructor(const OtherClass& other, double d);
+ ClassConstructor(const TOtherClass& other, double d) : _other(other), _d(d) {
- void method1() const;
- double calculation() const;
- double otherCalculation() const;
+ _a = 1/d;
+ }
- ~ClassDestructor() { }; // Yes, of course it's more sensibly named
- };
+ void method1() const {
+ // this method does nifty stuff.
- struct my_exception_type : public std::runtime_error {
- my_execption_type() : runtime_error("oops!") {
}
- virtual const char* what() const throw() {
- std::ostringstream cnvt;
- cnvt << runtime_error::what() ": Sorry, I shouldn't have done this...";
+ double calculation() const {
+ return _a + _d;
+ }
- return cnvt.str().c_str();
+ double otherCalculation() const {
+ return 0.; // I'm lazy
}
+ ~ClassDestructor() { }; // Yes, of course it's more sensibly named
};
편집을 시도합니다. (이 편집은 여기에서 끝났으므로,이 특정 편집본이 문제가되는지 아닌지 잘 모르겠지만, 내가 어떤 방식으로 편집 작업을했는지 알 수 있습니다.) 이러한 변화를 훨씬 쉽게 이해할 수 있다고 생각하지 않습니까? 분명히
- ClassConstructor(const OtherClass& other, double d);
+ ClassConstructor(const TOtherClass& other, double d) : _other(other), _d(d) {
+ _a = 1/d;
+ }
- void method1() const;
+ void method1() const {
+ // this method does nifty stuff.
+ }
- double calculation() const;
+ double calculation() const {
+ return _a + _d;
+ }
- double otherCalculation() const;
+ double otherCalculation() const {
+ return 0.; // I'm lazy
+ }
};
- struct my_exception_type : public std::runtime_error {
- my_execption_type() : runtime_error("oops!") {
- }
- virtual const char* what() const throw() {
- std::ostringstream cnvt;
- cnvt << runtime_error::what() ": Sorry, I shouldn't have done this...";
- return cnvt.str().c_str();
- };
,이 등 정확한 공 i 행의 수를 갖는 실수의 큰 위험하지만 내 문제는 그것이 모두 맞습니다 있는지 확인하기 어려운 것이 아니라 - 그것은 알아 내기도 어렵다 내가 뭘 잘못했는지.
이 질문이 도움이됩니까? http://stackoverflow.com/questions/3268596/git-add-interactive-your-edited-hunk-does-not-apply? – LeGEC
@LeGEC :이 질문은 문제 해결에 유용한 정보를 제공하지만 실제로 현재 가지고있는 것보다 더 많은 것을 할 수는 없습니다. 그 정보는 전혀 새로운 것이 아니며 현재 패치가 무엇이든 상관없이 현재 패치에만 해당되는 정보는 없습니다. 이 질문은'git' 자체에서보다 유익한 오류 메시지를 뽑아 낼 수있는 방법이라면 말입니다. –
나는 당신이 달성하고자하는 것을 완전히 이해했는지 확신 할 수 없습니다. git이 "line 1"이 실제로 "line 13"을 대체하고 "line 2"가 실제로 "line 26"등을 대체한다는 것을 기억하도록 패치를 편집하려고합니까? – LeGEC