git diff - What changed between here and there?

5.2.2. git diff - What changed between here and there?#

git diff   shows you what exactly changed between different files, branches and even repositories.

Create patches:

  • git diff > my.patch

  • git apply my.patch

Current changes:

  • git diff: Working Dir. vs. Staging

  • git diff --staged: Staging vs. HEAD

Example: git diff HEAD~2 HEAD:
diff --git a/example.py b/example.py
index 83db48f..84d55c5 100644
--- a/example.py
+++ b/example.py
@@ -1,7 +1,8 @@
 def greet(name):
-    print("Hello, " + name)
+    print(f"Hello, {name}!")
     return True
 
 def main():
+    print("Starting application...")
     greet("World")
Lines removed

Lines starting with - show content that was deleted

Lines added

Lines starting with + show content that was added