赞
踩
今天提交代码时,遇到只想提交类中部分代码的问题,之前也用过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;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
选择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的相关说明),所以不用修改,但如果发生了改变,则需要修改对应的-和+的行数。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。