New FAMILUG

The PyMiers

Saturday 2 December 2017

Dùng git diff với patch

git diff hiển thị các thay đổi bạn đã thực hiện mà chưa add, commit.
Output của git diff, trông, giống như diff (câu lệnh thường để so sánh 2 file).

patch là câu lệnh nhận vào file diff, và sửa các file có thay đổi tương ứng.
Trước khi GitHub trở nên phổ biến, người ta vẫn chia sẻ "bản vá" các phần mềm bằng các file diff, người nhận được sẽ patch (vá) các chương trình dựa vào file diff nhận được.



Đây là một file diff:


diff --git a/webpjvn/config.jinja2 b/webpjvn/config.jinja2
index 466b314..43f7b2b 100644
--- a/webpjvn/config.jinja2
+++ b/webpjvn/config.jinja2
@@ -1,5 +1,5 @@
 ListenPort = 8080
 DBUser = "pjvn"
 DBName = "pjvn"
-DBPassword = "{{ salt['password.pillar']('headloc:db:password') }}" # Share with headloc
+DBPassword = "{{ salt['pillar.get']('headloc:db:password') }}" # Share with headloc
 DBHost = "127.0.0.1"
diff --git a/webpjvn/init.sls b/webpjvn/init.sls
index 97846a4..7b09cf7 100644
--- a/webpjvn/init.sls
+++ b/webpjvn/init.sls
@@ -6,6 +6,7 @@ include:
   - postgresql.server
   - web
   - ssl
+  - supervisor
 /usr/local/webpjvn:
   file:
@@ -49,7 +50,7 @@ webpjvn:
   postgres_user:
     - present
     - name: pjvn
-    - password: {{ salt['password.pillar']('webpjvn:db:password', 10) }}
+    - password: {{ salt['pillar.get']('webpjvn:db:password', 10) }}
     - runas: postgres
     - require:
       - service: postgresql

Một máy tính khác, nếu có repo tương tự (vì một lý dó nào đó không commit và push được lên github), có thể copy nội dung file diff này, và chạy để patch trên máy mình:

Với câu lệnh 

patch -p1 difffile

Hết.
HVN at http://www.familug.org/ and http://pymi.vn

Tham khảo: https://stackoverflow.com/questions/4610744/can-i-get-a-patch-compatible-output-from-git-diff#4610846

Đăng ký học #Python tại https://pymi.vn/
Nhập email vào http://invite.pymi.vn/ để nhận thư mời tham gia forum hỏi đáp Python, Django, Golang, Linux ...


No comments:

Post a Comment