git add -p用法记录

今天提交代码时,遇到只想提交类中部分代码的问题,之前也用过git add -p,只是简单选择hunk就可完成任务,但今天的情况有所不同,特记录如下,加深一下记忆。

@@ -222,18 +219,22 @@ public class ReportImpl implements Report {
     }

     @Override
-    public ReportDto findById(String sn, String pw, long id) {
-        ReportDto result = new ReportDto();
+    public ReportDto findById(IdentityDto identity, long id) {
+        ReportDto result = null;
         try (Connection con = sql2o.open()) {
-            Report report = con.createQuery("SELECT * FROM Report WHERE Id = :Id")
+            Report report = con.createQuery("SELECT * FROM Report WHERE Id = :Id AND Deleted = 0 " +
+                    "AND HasLeft = 1 AND HasRight = 1")
                     .addParameter("Id", id)
                     .executeAndFetchFirst(ReportImpl.class);
-            mapper.map(report, result);
-            List<? extends ReportContent> contents = con.createQuery("SELECT * FROM ReportContent " +
-                    "WHERE Uuid = :Uuid")
-                    .addParameter("Uuid", report.getUuid())
-                    .executeAndFetch(ReportContentImpl.class);
-            setContent(result, contents);
+            if (report != null) {
+                result = new ReportDto();
+                mapper.map(report, result);
+                List<? extends ReportContent> contents = con.createQuery("SELECT * FROM ReportContent " +
+                        "WHERE Uuid = :Uuid")
+                        .addParameter("Uuid", report.getUuid())
+                        .executeAndFetch(ReportContentImpl.class);
+                setContent(result, contents);
+            }
         }
         return result;
     }

选择s后,Split into 3 hunks.

@@ -222,6 +219,6 @@

     }
     @Override
-    public ReportDto findById(String sn, String pw, long id) {
         ReportDto result = new ReportDto();
+    public ReportDto findById(IdentityDto identity, long id) {
        ReportDto result = null;
         try (Connection con = sql2o.open()) {

Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]?
对,这就是这里,只想提交这两行代码

-    public ReportDto findById(String sn, String pw, long id) {
+    public ReportDto findById(IdentityDto identity, long id) {
其他的修改,放在下次。看了Youtube上的视频后,发现编辑
@@ -222,6 +219,6 @@
很重要,但按照编辑窗口的说明,remove ‘+’和remove ‘-’替换成' '也没有成功,即:
     @Override
-    public ReportDto findById(String sn, String pw, long id) {
         ReportDto result = new ReportDto();
+    public ReportDto findById(IdentityDto identity, long id) {
        ReportDto result = null;
         try (Connection con = sql2o.open()) {
后来发现,需要调整为:

@@ -222,6 +219,6 @@
    }

     @Override
-    public ReportDto findById(String sn, String pw, long id) {
+    public ReportDto findById(IdentityDto identity, long id) {
         ReportDto result = new ReportDto();
         try (Connection con = sql2o.open()) {
即恢复成没有修改ReportDto result = null;的样子,然后对应的修改
@@ -222,6 +219,6 @@
这里恰好也是6行的6行(至于如何计算行数,还需查看diff的相关说明),所以不用修改,但如果发生了改变,则需要修改对应的-和+的行数。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值