Category: Git

Git: how to compare two branches

git commits

Sometimes it’s necessary to get the difference between two branches. Git already provides a really powerful diff command which does exactly this:

git diff

git diff is very powerful, as it not only compares two branches, it also allows multiple comparisons:

Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, changes resulting from a merge, changes between two blob objects, or changes between two files on disk.

https://git-scm.com/docs/git-diff

To compare two commits, simply use the commit hashes:

git diff 27b00e..f553c6

To compare two branches, simply use the branch names:

git diff master..feature/myNewFeature

The output looks like this:

diff --git a/lib/components/list_view/list_checkbox.dart b/lib/components/list_view/list_checkbox.dart
index 4985774..b3f5957 100644
--- a/lib/components/list_view/list_checkbox.dart
+++ b/lib/components/list_view/list_checkbox.dart
@@ -23,7 +23,7 @@ class ListCheckbox extends StatelessWidget
         checkColor: (checked && inactive) ? Colors.grey : Colors.black,
         onChanged: onChanged,
         activeColor: Colors.transparent,
-        focusColor: Colors.red,
+        focusColor: Colors.green,
       ),
     );
   }

Photo by Yancy Min on Unsplash

 

 

Sourcetree keeps asking for password

When Sourcetree keeps asking for password when committing or pushing data to a server, the following solution worked for me:

Go to terminal in your project folder and enter:

git config credential.helper store
git pull

Input your username and password and press enter. That’s it.

Source (somewhere in between the lines):
https://community.atlassian.com/t5/Sourcetree-questions/Sourcetree-keeps-asking-for-login-and-password/qaq-p/146765#M18512

VI oder VIM beenden

Um den bei vielen Linux und Unix Installationen und Tools (wie bspw. git) standardmäßig genutzten VI Editor zu beenden muss man mit der “ESC”-Taste in den Kommandomodus wechseln (am besten mehrfach drücken um ggf. schon eingegeben Kommandos abzubrechen). Und dort dann

> :q

eingeben und Enter drücken.
Dies beendet VIM wenn vorher nichts geändert wurde.

Wurde etwas am Text der geöffneten Datei geändert und man will dies speichern so nutzt man den Befehl:

> :wq

Will man die Änderungen verwerfen und VI verlassen, so hilft:

> :q!

Ein sehr hilfreiches und detailliertes Cheat Sheet zum Nachschlagen selten benutzter Befehle findet sich unter: https://devhints.io/vim

Auszug eines Cheat Sheets für VI/VIM

Git: Unterschied zwischen ‘git pull’ und ‘git fetch’

Kurz gesagt: git pull führt ein git fetch und anschließend ein git merge aus.

Ein git fetch kann man zu jeder Zeit machen, um die lokalen Branches zu aktualisieren und mit den entfernten Branches (origin, remote) abzugleichen. Diese Operation ändert dabei keine lokalen Branches, sie zeigt lediglich an, wenn Änderungen verfügbar sind. Man kann git fetch also bedenkenlos ausführen, ohne die lokale Arbeitskopie zu ändern.

Ein git pull führt ein git fetch und anschließend ein git merge aus. git pull wird dabei immer in den aktuellen Branch der Arbeitskopie mergen. Man wählt sich also den Branch aus, von dem man pullen möchte und pullt diesen (überführt dessen Änderungen) in den aktuellen Branch.

Ein git pull ist das, was man tun muss, um einen lokalen Branch auf den Stand des dazugehörigen entfernten Branch zu bringen.

Git documentation: git pullfetchmerge