Introduction
Today, a quick introduction in Git. In this blogpost a couple of familiar Git commands will pass and I will demonstrate the commands in small demos.
Installation
But first download the software of Git to your local machine and install the software locally. Verify the installation by using the following command : "Git version". This will return the current version of Git.
git version
In my case this results in the following version 2.28.0.
Demo
For this blogpost I created a folder with some files and I will experiment with these files : FileA, FileB and FileC.
And in every file I inserted the following phrase. This is and example for File A:
This is File A
Initialize the repository
When the file are there, the first statement that needs execution is Git init. This command creates an empty Git repository (basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master branch is also created.
Git init
A message appears when the initialization is ready.
Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.
Add the files to the repository
With git add you can add the files to the l(local) repository. It typically adds the current content of existing paths as a whole. This command updates the staging area (index) using the current content.
git add .
And now the files are added to the staging area. The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, and which haven’t, and which files aren’t being tracked by Git. The Git status output does not show you any information regarding the committed project history. For this, you need to use git log.
git status
Here the result of the git status. The files are in the staging area but they need to be committed.
git commit -m "new files"
Here the result of the commit of the files.
Now let's check the commit with "git status".
git status
So what have we done so far? We have added the files from the working directory to the staging area (aka index) with the "git add" command and with "git commit" we added the files from the staging area to repository.
git status
Git status reports that FileA is changed and these changes are not added and commit to the repository.
git add FileA.txt
git status
"Git status" reports that the file is changed and add to the staging are, now. But they need a commit to the repository.
git commit -m "FileA is changed"
git status
git log
And here is the result of the "git log". There are now two commits and HEAD is poinitng to the master.
The next step is changing fileC and add this file to the repository.
git status
git diff
git add FileC.txt
git commit -m "FileC- Changed"
git log
And now there are three commits and changes
"git checkout" command.
git checkout b81a42d23c48657dc976372d989a09e9cb6022ed
And now the original file is back.
git log
git checkout b81a42d23c48657dc976372d989a09e9cb6022ed
And now the last commit file is back
git log
Geen opmerkingen:
Een reactie posten