如何解决git add -i --patch仅限于一次拆分?

时间:2018-01-31 18:19:50

标签: git

git中使用git add -i --patch以交互方式添加修补程序时,可以选择将修补程序拆分为较小的部分。这些碎片有时非常大,没有选择再拆分。 Afaik编辑是唯一的选择。

如何在以下示例中git仅添加//test rest/user/randomofferincognito without authentication下的所有内容:

@@ -1500,13 +1532,35 @@
                 OfferRest.PATH,
                 OfferRest.UNREVIEWED_OFFERS_COUNT_METHOD))).openConnection();
-        uc1.setRequestProperty("Accept", MediaType.TEXT_PLAIN);
-        if(200 != uc1.getResponseCode()) {
-            Assert.fail(String.format("response code was %d and response text '%s'",
-                        uc1.getResponseCode(),
-                        IOUtils.toString(uc1.getErrorStream(),
-                                Charsets.UTF_8)));
-        }
-        restResponse = IOUtils.toString(uc1.getInputStream(),
+        uc2.setRequestProperty("Accept", MediaType.TEXT_PLAIN);
+        SeleniumHelper.assertResponseCodeEquals(Response.SC_OK,
+                uc2);
+        restResponse = IOUtils.toString(uc2.getInputStream(),
+                Charsets.UTF_8);
+        Assert.assertEquals("0",
+                restResponse);
+        //test rest/offer/reviewalloffers
+
+        //test rest/user/randomofferincognito without authentication
+        final HttpURLConnection uc3 = (HttpURLConnection) new URL(generateURL(String.format("rest/%s/%s",
+                OfferDevRest.PATH,
+                OfferDevRest.RANDOM_OFFER_INCOGNITO_METHOD))).openConnection();
+        uc3.setRequestProperty("Accept", MediaType.TEXT_PLAIN);
+        SeleniumHelper.assertResponseCodeEquals(Response.SC_UNAUTHORIZED,
+                uc3);
+        //test rest/user/randomofferincognito with authentication
+        HttpClient httpClient = HttpClientBuilder.create().build();
+        HttpGet httpGet = new HttpGet(generateURL(String.format("rest/%s/%s",
+                OfferDevRest.PATH,
+                OfferDevRest.RANDOM_OFFER_INCOGNITO_METHOD)));
+        httpGet.addHeader(BasicScheme.authenticate(
+                new UsernamePasswordCredentials("project1", ""),
+                "UTF-8",
+                false));
+        HttpResponse httpResponse = httpClient.execute(httpGet);
+        Assert.assertEquals(Response.SC_OK,
+                httpResponse.getStatusLine().getStatusCode());
+        HttpEntity responseEntity = httpResponse.getEntity();
+        restResponse = IOUtils.toString(responseEntity.getContent(),
                 Charsets.UTF_8);
         Assert.assertEquals("0",
                 restResponse);
Stage this hunk [y,n,q,a,d,/,K,g,e,?]? e

我从我不想添加的行中删除了+-,但该修补程序并未完全应用。我想我也必须改变线/偏移数,但是怎么做?

在某些用例中,可以使用git difftool作为解决方法,但这不是我的问题的一部分。

我有兴趣评论是否有必要建议支持多个拆分,即拆分拆分给git开发人员。

1 个答案:

答案 0 :(得分:1)

编辑补丁时,不需要添加或删除+和 - ,您需要创建一个可行的补丁。

这在git add的文档中有详细说明,但TL; DR版本是:

  • 如果您想保留已删除的行,请将 - 替换为空格
  • 如果您不想添加一行,请删除整行。