git Knowledge points summary
PrimaryWork flow
Working directory is the operating directory staging area is staging area, used to save changes repository is the repository, saved as a version of the change
Basic command git init git status git diff git log git reflog git add [. | filenames] git commit-m "message <=50 characters"
Head Head: Current version head^: Previous version head~n: last n versions sha:40 characters Unique identifier take at least 7 intermediate branches
GIT branch current branch git branch new_branch new branch git checkout branch_name switch branch git merge branch_name (provider branch name) merge to current branch Git branch -D branch_name Delete Branch
Note: If you have conflicting conflict, you need to modify it manually, then add, commit
Teamwork git clone remote_location (from) Clone_name (to) clone the remote repository to local git remote-v view the version information of the remote repository git fetch view remote modification (This operation was only incorporated into the local Origin/master, not local local/master) git push your_branch_name upload to remote
Note:
Origin/master flag The location of the remote head git fetch is different from git Pull:fetch does not automatically merge,pull automatically merge. Fetch safer using github requires you to fork to your account and clone from your account to commit the changes.
Work flow
The general workflow for versioning using Git is as follows:
①fetch and merge (=pull)
② Create new branch to develop new features
③ Development, Commit
④fetch and Merge
⑤push your branch to remote advanced
Reset and Checkout
This is the two common commands associated with fallback, exactly when to use which command, the specific usage and differences are as follows:
The reset command is generally used for version fallback: Note that there is more than one version fallback that can do the warehouse. Use the following:
Command format: Git reset [--parameters] [Commit-id] [filename] hard:head index Working Change mixed:head index Change (default) soft:head change
Add file name means only the file is fallback, not all files are rolled back
Checkout has two functions: switch branches and undo changes (refer to modify workspace, warehouse version also exists)
Undo Changes:
①git Checkout--[.| FileName
If add, go back to the state after Add. If there is no add, go back to the last commit
② workspace content back to last or last n versions
git checkout Commit-idfilenameor reset in checkout-two ways of comparison: The former is prone to misoperation, but retains the target version of the file workspace after several versions. The latter is not easy to operate by mistake, but several versions are lost. The wrong operation and solution of the former: filename must be added, if not added, the command will make the head pointer no longer point to the latest version, but in a free state. The workaround is to checkout to the Master branch, but cannot switch to the master branch if there are existing modifications. The new temp branch is created, the commit is merged into the master branch, and then the temp branch is deleted. You can return the head pointer to the latest version of the location. Git stash
The current branch work is not complete, no commit, but switch to another branch to work. The problem is that you cannot switch to another branch without commit modification. So we need to use the stash.
git stash backup git stash pop read and resume (pop command no longer has, after apply) git stash list git stash clear empty git stash apply [stash @{1}] git Stash drop [< stash;] Delete a progress, default latest
Note: You cannot save untracked files, you need to add the-u parameter to GitHub's use (Off-line)
Configure Git
①First, SSH key is created locally; ssh-keygen-t rsa-c "your_email@youremail.com"
The following your_email@youremail.com changes to the mailbox you registered on GitHub, and then asks for a confirmation path and a password, which we use as a default return line. Successful words will be generated under ~/. SSH folder, go in, open id_rsa.pub, copy the key inside.
Go back to GitHub, go to account Settings, choose SSH keys,add ssh key,title on the left, and paste the Key generated on your computer. Github-account
In order to verify success, enter it under git bash: ssh-t git@github.com
If it is the first time will prompt whether continue, enter Yes will see: You ' ve successfully authenticated, but GitHub does not provide shell access. This means that you have successfully connected to GitHub.
②Upload your local repository to GitHub, and you'll need to set up username and email before, since GitHub will record them every time it commits. git config–global user.name "your name" git config–global user.email "your_email@youremail.com"
Go to the repository you want to upload, right-click Git Bash, add remote address: Git remote add Origin git@github.com:yourname/yourrepo.git
The following yourname and Yourrepo indicate that you re-github user name and the newly created warehouse, added after the addition of the. git, open config, here will be a remote "origin" content, this is just added to the long-range address, You can also modify config directly to configure the remote address.
③Create a new folder, open it, and then execute GIT init to create a new git repository.
Check out the Warehouse
Execute the following command to create a cloned version of the local repository:
Git clone/path/to/repository
If this is the repository on the remote server, your command will look like this:
git clone username@host:/path/to/repository