Git Usage Tutorials
For more details, please refer to: Liaoche's official website-git tutorial
1. Install the GIT client software
Git for Windows http://msysgit.github.io/
2. Create a version library
Two-point content:
Initialize a git repository, using git init
commands.
Add files to the Git repository in two steps:
- The first step, use the command
git add <file>
, note, can be used repeatedly, add multiple files
- The second step, using
git commit [-m "备注信息"]
the command, is done.
3. Time Travel Machine
- Use the command to keep track of the status of the workspace (if any files have changed, if any files have been add to commit, and so on)
git status
.
- If
git status
you're told that a file has been modified, use Git diff to see what's changed.
git diff 文件
See what's changed
git 文件
View File Contents
3.1. Version fallback
- The version that head points to is the current version, so git allows us to navigate between versions of history, using commands
git reset --hard commit_id
.
- Before the shuttle, use git log to view the commit history to determine which version to fallback to.
- To return to the future, use Git reflog to view the command history to determine which version to go back to in the future.
3.2. Workspaces and Staging Area
- The workspace has a hidden directory. Git, this isn't a workspace, it's a git repository.
- When we added the file to the Git repository, it was done in two steps:
- The first step is to use git add to add the file, in fact, the file is modified to add to the staging area;
- The second step is to commit the change with git commit, which in effect commits all of the staging area content to the current branch.
- Because git automatically created the only master branch for us when we created the Git repository, now git commit is committing 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.
3.3. Management changes
- Git tracks and manages changes, not files.
- Each time you modify, if you do not add to staging area, you will not be added to the commit.
3.4 Undo Changes
- When you mess up the contents of a file in your workspace and want to discard the workspace changes directly, use the command git checkout-file.
- When you not only changed the contents of a file in the workspace, but also added to the staging area, want to discard the changes, two steps, the first step with the command git reset HEAD file, back to scene 1, the second step by scene 1 operation.
- If you have submitted an inappropriate modification to the repository, you want to revoke this commit and refer to the version fallback section, but only if it is not pushed to the remote library.
3.5 Deleting files
- In general, you usually delete the useless files directly in the file manager.
- At this point, git knows you deleted the file, so the workspace and repository are inconsistent, and the
git status
command will immediately tell you which files were deleted.
- Now you have two options:
- The first is to remove the file from the repository, then delete it with the command
git rm
, andgit commit
- The other is wrong, because the repository is still there, so it is easy to restore the deleted files to the latest version:
$ git checkout -- test.txt
Remote Warehouse Create a remote repository
In general, we use third-party git remote repositories, such as domestic coding.net. In the coding background page, we have seen the Create Item button, we first create the project.
Open git Client Connection warehouse
- Locate the location on our local computer and create a new folder that is dedicated to storing the files for this new warehouse. Then go to this folder, right mouse, choose Git bash option to open git command box.
Connect to the remote repository. Here we need to find the https file path from the remote repository first.
git clone git.coding.net/MyCount/Test.git(我们自己的仓库路径)
After the download we can look at the local folder is not a lot of files, our remote repository files to download to the local.
Add and submit Notes
Enter the project file root directory
cd Test //进入项目文件根目录ls //ls命令检查GIT中是否可以看到已经提交到的文件
Move the file that you want to upload to the remote repository to the local warehouse folder
git status //查看当前的文件状态,已经有变化文件是需要上传到远端仓库的。
Add files to cache and submit notes
git add * (或者文件名) //git add命令添加需要上传的文件到缓存中git commit -m "备注信息"
Push file
git push origin master //进行推送文件到仓库,因为我们没有使用公钥绑定,所以每次提交时候需要输入CODING的用户名和密码,这样也好,确保安全。//之后在提示框输入账号和密码即可
Git Usage Tutorials