Git
October 1, 2021
home
Contents
01. My experience with Git
My first impression
- Git is the most recognized generic computer source code version control tool.
- Just like any others, Git has some definitions like checkout has its unique meaning.
- I use MAC, and use a web devlopment for this demo.
- After installed Git in my mac, do the following.
- In my terminal window, under any folder, $git --version to verify the installation.
- git is also a command name.
- git config --global user.name "johndoe"
- git config --global user.email "johndoe@xyz.com"
- notes: For team softwares, author's name matters.
- The above is device level, you only do once.
- The following are the examples why you use git.
- If you want to publish a Django website to Heroku for hosting. Heroku requires git to do so.
- If you want to send code to a remote public repositories like Github for many reasons.
- It is required by your team.
- You want to do so. When you append a lots of code. And you find wrong, and want to remove them.
- The first step to develop a web site development project is to create a project folder.
- After that, create many files for html, css, js, images. And test them in your local browser
- Under the project folder, execute $git init. It is to initialize Git on that folder. A subfolder .git is created.
- $git status
- From the return message,you'll see that all the files are untrack.
- It means they are in the working folder, they are not moved to the staging area.
- $git add --all. It is to add all into the staging area.
- From the return message, you see No commits yet.
- You also see "On branch master"
- Here, only branch is involved.
- git commit -m "First release of project x"
- They are moved into the local repository.
- $git status. You see the message, nothing to commit, working tree clean
- git log --oneline. You see message like d93adee(Head) first commit.
- The hex number is the pointer for this commit.
- When you push your code out, the files in local repository, not working folder, will be pushed out.
- After your commits, the contents among three areas are the same. You can test them from the working folder.
02. Continue to commit, Return to One Previous Commit using git checkout
- In the previous lab, there is one commit.
- Change code by update, delete, $git add --all, commit it as the second commit.
- $git log --oneline, you see the response message as below:
- dc77ee2 (HEAD) second commit
- d93adee first commit
- $git checkout d93adee to remove the second commit
- $git log --oneline
- You see the respone, d93adee first commit. The head is point to the first commit.
- $cat index.html. The code change in the second commit is removed.
- note: If the second commit involing add files, those files will be deleted in working folder after checkout.
- The keyword checkout here means code reset.