Welcome everyone

git patch

java 汪明鑫 16浏览 0评论

git patch 应用场景 : code review     代码迁移

git patch 是针对一个或多个commit的

 

实操一波大家就知道了

 

git log

 

 

 

看看这个patch文件

From d2560be8adb95e9b59dae010a451b97415c59364 Mon Sep 17 00:00:00 2001
From: wangmingxin03 <wangmingxin03@kuaishou.com>
Date: Tue, 19 May 2020 21:15:38 +0800
Subject: [PATCH] joda-time

---
 pom.xml                                       |  7 ++++
 .../springbootfreemarkerdemo/TimeTest.java    | 42 +++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 src/test/java/pers/wmx/springbootfreemarkerdemo/TimeTest.java

diff --git a/pom.xml b/pom.xml
index f1d94e7..68441cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,6 +87,13 @@
             <version>2.6</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>2.9.9</version>
+        </dependency>
+
         <!-- memcache -->
         <dependency>
             <groupId>net.spy</groupId>
diff --git a/src/test/java/pers/wmx/springbootfreemarkerdemo/TimeTest.java b/src/test/java/pers/wmx/springbootfreemarkerdemo/TimeTest.java
new file mode 100644
index 0000000..aece596
--- /dev/null
+++ b/src/test/java/pers/wmx/springbootfreemarkerdemo/TimeTest.java
@@ -0,0 +1,42 @@
+package pers.wmx.springbootfreemarkerdemo;
+
+import org.joda.time.DateTime;
+import org.joda.time.LocalDateTime;
+
+/**
+ * @author: wangmingxin03
+ * @date: 2020-05-19
+ */
+public class TimeTest {
+
+    public static void main(String[] args) {
+        DateTime nowTime= DateTime.now();
+
+        int year = nowTime.getYear();
+        System.out.println(year);
+        int weekYear = nowTime.getWeekyear();
+        System.out.println(weekYear);
+
+        System.out.println(nowTime.getWeekOfWeekyear());
+        System.out.println(nowTime.getDayOfWeek());
+        System.out.println(nowTime.getDayOfYear());
+
+        DateTime dateTime = new DateTime(
+                2019, //year
+                1,    // month
+                1,    // day
+                1,    // hour (midnight is zero)
+                0,    // minute
+                0,    // second
+                0     // milliseconds
+        );
+
+        System.out.println(dateTime.getWeekyear());
+        System.out.println(dateTime.getWeekOfWeekyear());
+
+        DateTime lastWeek = dateTime.minusWeeks(1);
+        System.out.println(lastWeek.getWeekyear());
+        System.out.println(lastWeek.getWeekOfWeekyear());
+
+    }
+}
-- 
2.26.0

 

我们怎么使用这个patch 文件

去另一个项目里或者我们想在当前分支恢复一些误删的代码,也可以直接把patch 文件发给别人导入代码

简单来说,就是可以把patch文件在需要的工程中应用,引入commit中的代码

 

 

 

 

转载请注明:汪明鑫的个人博客 » git patch

喜欢 (0)

说点什么

您将是第一位评论人!

提醒
avatar
wpDiscuz