To create a version library
mkdir: Creating Files
PWD: Show current directory
Ls-ah: View the contents of the current file subdirectory
Git init: Turn the current directory into a repository that git can manage;
git add: Tell git to add files to the repository, use them repeatedly, and add multiple files.
Git commit-m "": After m input is the description of this submission
: 1 files were modified, 2 lines of statements were newly inserted.
Time Machine Shuttle
Git Status: Command allows us to keep track of the current state of the warehouse
: Readme.txt has been modified, but no changes are yet ready to be submitted.
git diff: If git status you're told that a file has been modified, you git diff can see what's changed. git diff HEAD--readme.txt: See the difference between the latest version.
: You can see from the command output above that we added a "distributed" word to the first line.
Version fallback
git log: command displays the commit log from the most recent to the farthest, if too much output information, can lose: Git log--pretty=oneline
git reset--hard head^: Back to the previous version, the last version is HEAD^^ , of course, 100 to write 100 is ^ more easy to count, so write HEAD~100 . (Back to the past)
git reset--hard3628164:举例,(回到未来)
Git reflog--you fall back to a version, turn off your computer, regret it the next morning, can't find a new version ofcommit id,用这个命令。
undo Changes
(You can use Git status to prompt yourself)
Git checkout-File: Scenario 1: When you mess up the contents of a file in your workspace and want to discard the workspace changes directly
git reset HEAD file: Scenario 2: When you not only change the contents of a file in the workspace, but also add to the staging area, you 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.
Scenario 3: When an inappropriate modification to the repository has been submitted, you want to revoke this commit, refer to the version fallback section, but only if it is not pushed to the remote library.
Deleting Files
RM command, delete files after two selections
1. One is to delete the file from the repository, it is deleted with the command git rm test.txt , andgit commit
2. Another situation is that the deletion 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
1. Add a remote Library
To create a learngit warehouse (example) on ①:github, we run the command in the local repository according to GitHub's prompts learngit :
$ git remote add origin git@github.com:muyunyun/learngit.git
添加后,远程库的名字就是origin,这是Git默认的叫法,也可以改成别的,但是origin这个名字一看就知道是远程库。
Ii:$ git push -u origin master(
Pushing the contents of the local library to the remote, with git push the command, is actually pushing the current branch master to the remote.
Since the remote library is empty, the first time we push master a branch, with -u parameters, Git will not only master push the local branch content of the remote new master branch, but also the local branch and the master Remote master Branch Association
)
③: From now on, as long as the local submission, you can through the command
$ git push origin master
2. Cloning from a remote library
If the repository to be Gitskills is cloned locally:
$ git clone git@github.com:muyunyun/gitskills.git
GitHub gives more than one address, but can also use https://github.com/michaelliao/gitskills.git such an address, but with the fastest ssh native git protocol supported.
Branch Management
To create and merge branches:
Git branch: View branches;
Git branch <name>: Creating branches;
git checkout <name>: switch branches;
Git checkout-b <name>: Create + switch branches;
git merge <name>: Merges a branch into the current branch;
Git branch-d <name>: deleting branches
Branch Management Policy:
Git merge--no-ff-m "merge with No-ff" <NAME>: Branching information can be seen from the branch history
Bug Branch:
When fixing a bug, we will fix it by creating a new bug branch, then merging and finally deleting;
When the work is not finished, first put the job site git stash , and then go to fix the bug, repair, and then git stash pop back to the job site.
Multi-person Collaboration:
View Remote library information, use git remote -v ;
Local new branches are not visible to others if they are not pushed to the remote;
Push branches from local, use git push origin branch-name , if push fails, first use git pull crawl remote new commit;
Local and remote branches corresponding to the branch, use git checkout -b branch-name origin/branch-name , local and remote branch names are best consistent;
Establishing the Association of local and remote branches, using git branch --set-upstream branch-name origin/branch-name ;
From the remote crawl branch, use git pull , if there is a conflict, you must first handle the conflict.
Label Management
The command is git tag <name> used to create a new label, either by default HEAD or by specifying a commit ID;
git tag -a <tagname> -m "blablabla..."Label information can be specified;
git tag -s <tagname> -m "blablabla..."Can be signed with PGP tag;
Command git tag to view all tags.
Recommend the Liaoche Teacher's git tutorial.
Common git commands