1. Installation
Install the GIT for Windows program online first.
Enter the following in the Gitbash
" Your Name " --global user.email [email protected]
2. Create a version library
Find a directory According to your preferences create a folder, I choose e:/mygit/
Right--git bash here, enter this directory into a repository that git can manage
$ git init
Found in the current directory more than one .git
directory, this directory is git to track the management version of the Repository, do not manually modify the files in this directory, or change the mess, the Git repository to destroy.
3. Add files to Repository
Create a Readme.txt in the current directory with the contents of
free software.
Add a file to the warehouse with add
$ git Add readme.txt
Commit the file to the warehouse with a commit
" wrote a readme file " [Master (Rootfile1, file2 insertions (+100644 Readme.txt
Time Travel Machine
We continue to change the Readme.txt file to the following:
free software.
Run the git status command to see the results of the changes
Run the git diff command to see the records before and after the changes
Version fallback
Modify Readme.txt
free software distributed under the GPL.
After committing, use git log to view the history of the commit, fallback to the previous version with the following command
$ git reset--hard head^
head^ refers to the last commit of the current commit
If you fall back and want to go back? Then you can find the commit ID and enter the following as well.
ID>
The version number is not necessary to write the whole, the first few can be, git will automatically go to find. Of course, you can't just write the top one or two bits, because git might find multiple version numbers, and there's no way to determine which one.
In addition, GIT provides a command git reflog
to keep track of every command you make.
If you fall back to a version, turn off the computer, regret the next morning, want to restore to the new version but can not find a new version of thecommit id,就用git reflog来查看。
Workspaces and Staging Area
Workspaces (working directory), which is the directory on our Computers
Repository (Repository), which is the. git in our directory.
Git has a lot of stuff in its repository, the most important of which is the staging area called stage (or index), and the first branch master that git automatically creates for us, and a pointer to master called head.
We add files in two steps
The first step is to add the file git add
, in effect, to add the file to the staging area;
The second step is to commit the git commit
changes, in effect, to commit all the contents of the staging area to the current branch.
Since we created the Git repository, Git automatically created the only branch for US master
, so now it's time to git commit
commit the changes to the master
branch.
You can simply understand that the file changes that need to be submitted are all put to staging area, and then all changes to staging area are submitted at once.
Undo Changes
Modify the Readme
Free software distributed under the GPL. Git has a mutable index called stage. Git tracks changes of files. My stupid boss still prefers SVN.
Before you prepare to submit, a cup of coffee has played a role, you suddenly found that "stupid boss" may let you lose this month's bonus!
Now that the error has been found in time, it can be easily corrected. You can delete the last line, manually restore the file to the previous version of the state. If you take a git status
look
You can see that git will tell you that you git checkout -- file
can discard changes to the workspace:
$ git checkout--readme.txt
deleting files
RM <file name> It's OK after a commit.
git for Windows