DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1

Click here to view code image


#git diff --cached
diff --git a/text2 b/text2
new file mode 100644
index 0000000..b9997e5
--- /dev/null
+++ b/text2
@@ -0,0 +1 @@
+new bit of code

git diff identified the new file addition and shows the
a/b comparison. Since this is a new file, there is nothing
to compare it with, so you see --- /dev/null as the a
comparison. In the b comparison, you see +++ b/text2,
which shows the addition of the new file, followed by
stacks on what was different. Since there was no file
before, you see -0,0 and +1. (The + and - simply denote
which of the two versions you are comparing. It is not
actually a -0, which would be impossible.) The last line
shows the text that was added to the new file. This is a
very simple example with one line of code. In a big file,
you might see a significant amount of text.


Another very useful capability of git diff is to compare
branches. By using git diff (branchname), you can see
the differences between a file in the branch you are
currently in and one that you supply as an argument. The
following compares text1 between the branches master
and newfeature, where you can see that line 3 is present
on newfeature branch’s text1 file:


Click here to view code image


#git diff newfeature text1
diff --git a/text1 b/text1
index 45c2489..ba0a07d 100644
--- a/text1
+++ b/text1
Free download pdf