Git Learning Notes

Source: Internet
Author: User
Tags using git

1, git init create repository (repository). Created in the current directory, the default is hidden file on Mac, ls-a can see
2. Git add and git commit are used to submit the file. The reason for the two process is that git commit can commit multiple files at a time, so you can add git multiple times. Git add actually adds the file to the staging area stage (or index). And Git commit is to commit the content in staging area to the current branch.
The important parameter of git commit "-M", usage-M "xxx" is used to add description for this submission.
Each "snapshot" in Git is called a commit.
3, Git status View the current status, when there are changes will give the corresponding results. For example, the xxx file has been changed but not submitted.
You need to use Git diff to see what's changed
4. Submit a new document as amended. Also git add and git commit-m "xxx"
5. Use git log to view the history of each version. Use--pretty=oneline simplifies output
6, git use head to represent the current version, the previous version added ^ For example, the previous version is head^, the previous is head^^, up to n versions can be written head~n
Back to the previous version is Git Reset–hard head^
At this point, log will find that the previous version is missing and you can use git reset--hard to return to the "future" version. Commit ID does not need to be all, the first few can (also not too short)
If you forget the commit ID of a future version, you can use Git reflog to view each previous instruction.
7. Use git checkout-erase this uncommitted change.
When the file has not been placed in staging area since it was modified, it is returned to the state before the modification.
When the file is staging area and modified, it is returned to the state after it has been placed in staging area.
When a file is deleted from the workspace, it can be restored (because there are repository)
8. Use git reset HEAD to undo the changes that have been added to the staging area and back to the workspace.
9. Delete the workspace-after the commit file, you can use git rm to delete the files in repository, and Git commit is required.
10, remote warehouse. Settings before using the GitHub remote repository:
① Create SSH key, when you can ls-a in the home directory to see if there is a. SSH directory, and see if there are Id_rsa and id_rsa.pub files, if any, then skip to the next step, if not, use Ssh-keygen-t rsa-c under the terminal "[email Protected] "command to create SSH Key.
Id_rsa is the private key, Id_rsa.pub is the public key, you can tell others.
② Login to GitHub, open settings, click "Add SSH Key", fill in any title, and then paste the contents of the id_rsa.pub into the Key text box.
11. Create a warehouse on GitHub. Log on to GitHub and click Create a new repo. Enter instructions in the local warehouse directory git remote add origin [email protected]:yourname/yourpath.git
Where origin is the default, representing the remote library.
You can then push the contents of the local repository to the remote repository.
Input instructions git push-u origin master
GitHub Recommended Practice: Use HTTP instead of [email protected] ...
Reset Remote Library url:git remotes Set-url origin
The first time you push the master branch with the-u parameter, git associates the local master with the remote master. simplifies subsequent operations.
After a local commit, the latest modification of the master branch is push to the remote repository by the command GIT push Origin master.
12, clone other people's repository
First you need an repository address, then use Git clone to
13, Branch.
Use Git branch to view all current branches, with * identifies the current branch
Create a new branch with Git branch ... ①
Switch to Branchname branch using git checkout ... Ii
The above ①,② can be combined into one instruction git checkout-b
Merge Branchname into the current branch using git merge (quick merge)
Delete a branch using git branch-d
14, when the changes do not conflict, you can fast-forward merge. If all two branches have been modified and conflicting, you cannot use quick merge. Use git status to view conflicting files. You should make the appropriate changes in the file, then add and commit to complete the merge.
You can use git log--graph--pretty=oneline--abbrev-commit to view the merge of the branches.
(Git log--graph is to view the branch merge diagram, the following parameters are simplified output)
15, non-rapid merger (teamwork): If you use quick Merge, merging and deleting branches will not be able to see that there have been branches, so you can use a non-quick merge.
Enter git merge--no-ff-m "..." directive, parameter--NO-FF indicates a non-fast merge, because this merge is to create a new commit, so add-m parameter and fill in the description.
In team development, the master branch is used only to publish new versions, usually working on the dev branch. Everyone has a branch of Dev, and occasionally merges to dev.
16. When a bug is to be fixed, a new branch is usually created. If the current branch work is not completed, it cannot be submitted. You can use Git stash to save the field and use the Git stash list to view all of the current staging sites.
Use git stash apply to restore the scene, but stash content is not deleted
Using Git stash drop can delete the scene, if not restore the site directly delete it, it will not be retrieved?.
Use git stash pop to do the top two actions at the same time
The above three instructions can be added after the [email protected]{.} Where. Represents the ordinal number of the stash that is found through the Git stash list. Indicates that a site is designated for recovery/deletion.
17. Use Git branch-d to forcibly delete a branch that is not merged.
Typically new features create a new feature branch on the Dev branch and develop it on the feature branch.
18. Use git remote-v to view remote library information.
Use GIT push origin to push branches remotely. If it fails, crawl the remote new commit with Git pull. If the local branch and remote branch relationships are not created, use Git branch--set-upstream-to=origin/.
Note that git branch--set-upstream branch-name Origin/branch-name has been abandoned.
19, label.
Create a tag with git tag, which is on the head by default, and you can specify a commit ID later.
Use git tag-a-M "..." to specify label information. The tag name is followed by-M, which is the descriptive information.
Use git tag-s-M "..." to sign the tag with PGP.
Use git tag to view all tags.
Use git show to show tag information.
Push native tags with git push origin
Use GIT push origin--tags to push all the non-push tags.
Delete a local label using Git tag-d
Delete a remote label using git push origin:refs/tags/
20, the role of fork. You can fork any open source library on GitHub, fork yourself with a copy of repository, and have read and write rights to push pull request to the official to contribute code.
21.. gitignore file function: Write the file name to ignore, Git will automatically ignore these files.
The. gitignore file also needs to be submitted.
22. configuration files and aliases.
Use git config--global alias. Sets the alias for Real_name.
The configuration file is placed in the. git/config file, the alias is within the [alias] block, and deleting the alias only requires deleting the corresponding row.
The global configuration file is placed in the. gitconfig file in the home directory.

Git Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.