Jeśli używamy Gita na pewno znamy polecenie
git log
które to wyświetla nam historię zmian w repozytorium. Jednak polecenie to ma pewną ciekawą możliwość, którą daje nam przełącznik -L.
Mianowicie wówczas możemy podać nazwę metody oraz nazwę pliku i wyświetli nam się cała historia, ale dotycząca zmian w tej konkretnej metodzie. Jest to naprawdę wygodne, gdy chcemy dokładnie przyjrzeć się zmianom tylko w jednym miejscu bez przedzierania się przez rozbudowane porównywanie i całe pliki. Mój przykładowy plik Demo.cs wygląda tak:
using System;
public class Demo
{
public void Demo()
{
// Here is the third change
}
}
Wywołanie polecenia gita:
git log -L :Demo:Demo.cs
Zwróci coś takiego:
commit b37ad38a5ebc75e0b54f036e137832368fae754f
Author: Maga <iwona.lalik@gmail.com>
Date: Sun Apr 16 21:50:47 2017 +0200
next change
diff --git a/Demo.cs b/Demo.cs
--- a/Demo.cs
+++ b/Demo.cs
@@ -3,7 +3,7 @@
public class Demo
{
- public static void Main()
+ public void Demo()
{
// Here is the third change
}
}
\ No newline at end of file
commit fadf9afd23f8008e3514f183a9873442dcd597d1
Author: Maga <iwona.lalik@gmail.com>
Date: Sun Apr 16 21:50:25 2017 +0200
next change
diff --git a/Demo.cs b/Demo.cs
--- a/Demo.cs
+++ b/Demo.cs
@@ -3,7 +3,7 @@
public class Demo
{
public static void Main()
{
- // Here is the second change
+ // Here is the third change
}
}
\ No newline at end of file
commit be56749b09a606f0137c993d0df03fa336e88701
Author: Maga <iwona.lalik@gmail.com>
Date: Sun Apr 16 21:48:03 2017 +0200
Second change
diff --git a/Demo.cs b/Demo.cs
--- a/Demo.cs
+++ b/Demo.cs
@@ -3,7 +3,7 @@
public class Demo
{
public static void Main()
{
:
{
public static void Main()
{
- // Here is the second change
+ // Here is the third change
}
}
\ No newline at end of file
commit be56749b09a606f0137c993d0df03fa336e88701
Author: Maga <iwona.lalik@gmail.com>
Date: Sun Apr 16 21:48:03 2017 +0200
Second change
diff --git a/Demo.cs b/Demo.cs
--- a/Demo.cs
+++ b/Demo.cs
@@ -3,7 +3,7 @@
public class Demo
{
public static void Main()
{
- // Here is the first change
+ // Here is the second change
}
}
\ No newline at end of file
commit bb7f033cdc9edce4eed0f7c30031b50d2cfc99d5
Author: Maga <iwona.lalik@gmail.com>
Date: Sun Apr 16 21:47:46 2017 +0200
First change
diff --git a/Demo.cs b/Demo.cs
--- a/Demo.cs
+++ b/Demo.cs
@@ -0,0 +3,7 @@
+public class Demo
+{
+ public static void Main()
+ {
+ // Here is the first change
+ }
+}
Są tutaj zmiany uporządkowane od najnowszych od najstarszych. W moim demonstracyjnym przypadku zmiany polegały jedynie na zmianie komentarza a następnie nazwy metody, ale oczywiście w prawdziwych plikach będzie tego dużo więcej. W konsoli jest to oczywiście wszystko podświetlone – zmiany usunięte są napisane czerwoną czcionką dodane zieloną.



