1. Background
Recently, I plan to use git to manage local projects. There is a lot of information on the Internet, but this is complicated.
2. Use git
(1) initialization
Create a git folder, cd in, and create a code repository
Git init
Go to the folder and hide the file. The. git file is generated, as shown in figure
Put the project to be managed in this git folder, or clone the required project from the server. I put testDraft in.
Enter the following command to view the status.
Git status
It will prompt you for git add or git commit this operation. Because we added a project to the code library and didn't add it to the git sequence, because git is distributed and managed, we need to add each file to the head directory, the commit description is required for each modification. The following describes the project.
Git add testDraft
Git commit-m "init the project"
Then git will list all the modifications made this time.
(2) modify and restore a file
First, we can modify a file, resource. properties. As shown in figure
Add a paragraph in it, "this is a test"
Then, add and commit the file and submit the file.
28852262 @ cnbjlx20155 :~ /Git $ git add testDraft/resource. properties
28852262 @ cnbjlx20155 :~ /Git $ git commit-m "test1"
We can view this modification.
Git log
We can see that the hash code of each commit
Copy any hash code and enter the following code to view the changes.
Git show dcf7c11e403f7e4ff129aab01e6b6962e1120a77
Next we will use the restoration function to return to before adding this is a test statement.
First, copy the modified commit code, that is, the yellow code in
Enter git revert + yellow code in shell
Git revert dcf7c11 .......
The following content is displayed:
Press ctrl + x to exit and find that "this is test" has been deleted.
Git details: click here
Git: click here
Recommended reading:
Fedora downloads Git through Http Proxy
Install Git on Ubuntu Server
Create a Git repository on the server (Ubuntu)
Git simple tutorial in Linux (taking Android as an example)
Git authoritative guide PDF