代码之家  ›  专栏  ›  技术社区  ›  Kalle Richter

如何解决git add-i补丁被限制为一个拆分的问题?

git
  •  1
  • Kalle Richter  · 技术社区  · 8 年前

    在中以交互方式添加面片时 git 具有 git add -i --patch 可以选择将补丁分割成更小的部分。这些碎片有时非常大,无法再次拆分。Afaik编辑是唯一的选择。

    我怎样才能 吉特 仅添加下面的所有内容 //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 作为一种解决方法,但这不是我问题的一部分。

    我很想发表评论,建议支持多个拆分(即拆分的拆分)是否有意义 吉特 开发人员。

    1 回复  |  直到 8 年前
        1
  •  2
  •   LightBender    8 年前

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

    有关详细信息,请参见 git add ,但TL;DR版本为:

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