Git notes sorting and git sorting

Source: Internet
Author: User

Git notes sorting and git sorting


1. Install Git

1. Install git. Click Git Bash to go to the command line window.
2. Configuration:
$ Git config -- global user. name "Your Name"
$ Git config -- global user. email "email@example.com"
Note that the -- global parameter of the git config command uses this parameter to indicate that all Git Repositories on your machine will use this configuration, you can also specify different user names and Email addresses for a repository.

 

Ii. Create a version Library
1. Create an empty directory (mkdir <folder Name>). You can view the current directory through pwd (note: the directory name should not contain Chinese characters)
2. Use git init to change the directory to a Git-managed repository. After executing this command, you can use ls-ah to view the hidden file. git under this directory.
3. Use the command git add <File Name> to submit the file to stage (temporary storage area)
3. Run the git commit command <-m "XXX"> to submit all the files in the temporary storage area to the Git version library.

 

3. Master two Commands
1. view the status of the workspace in git status
2. git diff to check the file modifications

 

Iv. Version rollback
1. Run the git log command to view all logs that have been committed. If there is too much information, add -- pretty = oneline
2. In Git, HEAD indicates the current version.
--- Previous version HEAD ^
--- Previous version HEAD ^
--- First 100 versions of HEAD ~ 100
3. Return to the command git reset -- hard HEAD ^ of the previous version.
4. Go back to a future version of git reset -- hard 3628164 (followed by a commit_id)

 

5. Work zone and temporary storage Zone
1. Understand the work zone and temporary storage zone Mode

 

6. manage changes
1. Run git diff HEAD -- <File Name> to view the differences between the latest version in the workspace and the version Library:

 

VII. Undo Modification
1. git checkout -- <File Name>:
Readme.txt has not been put into the temporary storage zone after modification. Now, undo the modification and return to the same status as the version database;
(The preceding note is that the readme.txt file has been added to stage before. If you want to know the last modification after modifying it in the workspace, use this command)

One is that readme.txt has been added to the temporary storage area and is modified again. Now, undo the modification and return to the status after it is added to the temporary storage area.
2. Run git reset HEAD -- <File Name> to unstage the changes in the temporary storage area and put it back into the workspace.

 

8. delete an object
1. delete the files in the workspace directly. You can use rm <File Name>
2. You need to delete the files in the git version library, use git rm <File Name>, and then execute git commit.
3. Note: if the file in the workspace is deleted incorrectly and still exists in the git version library, you can use git checkout to retrieve the file name;

 

9. remote warehouse
1. Because you need to connect to the remote repository via SSH, you need to use $ ssh-keygen-t rsa-C "youremail@example.com" locally to generate a signature
If everything goes well, you can find the. ssh directory in the user's home directory, which contains two files: id_rsa and id_rsa.pub. These two are the SSH Key's Key pair, and id_rsa is the private Key,
It cannot be disclosed. id_rsa.pub is the public key and can be safely told to anyone.
2. Step 2: log on to GitHub and open the "Account settings" and "SSH Keys" page.
Click "Add SSH Key", fill in any Title, and paste the content of the id_rsa.pub file in the Key text box.



10. Add a remote database
1. First, log on to GitHub and find the "Create a new repo" button in the upper right corner to Create a new repository.
2. Fill in learngit in the Repository name. Keep the default settings for others. Click "Create repository" to Create a new Git Repository.
3. Associate the local repository with github by adding origin git @ server-name: path/repo-name.git through $ git remote
(For example: $ git remote add origin git@github.com: michaelliao/learngit. git)
4. During the first push, use $ git push-u origin master to push all the content of the local database to the remote
(Note: Because the remote database is empty, when we push the master branch for the first time, the-u parameter is added, Git not only pushes the content of the local master branch to the remote new master branch,
It also associates the local master branch with the remote master Branch, which can simplify the command for later pushing or pulling .)

 


11. Clone from remote database
1. First create a remote library and clone the project through git clone git@github.com: michaelliao/gitskills. git
2. Git supports multiple protocols, including https, but the native git protocol supported by ssh is the fastest.

 

12. Create and merge branches
1. in version rollback, you can see that there is a default timeline. This line is a master branch, that is, the master, and the HEAD actually points to the master and the master points to the submitted, so the HEAD points to the current anti-split.
2. Each time the job is submitted on the master node, the branch moves one step forward.
3. When we create a new branch (dev), the branch points to the same commit as the master. When we switch to the dev branch, the HEAD points to dev.
4. When it is submitted on dev, dev moves one step forward, while the master pointer remains unchanged.
5. Create the branch command $ git branch dev; Switch the branch $ git checkout dev. The first two commands can be completed through $ git checkout-B dev.
6. view the branch $ git branch to list all the branches. There will be a * sign before the current branch.
7. After switching the branch, modify the content and submit it to the Branch. If you want to merge the submission to the master branch, you must first switch to the master branch $ git checkout master
8. merge to master $ git merge dev
9. Delete the original branch $ git branch-d dev

 

13. Conflict Resolution
1. develop on the dev branch. After the development is complete, submit it to the Branch. Then, switch to the master branch and submit the content on the master branch, then merge the submission on the dev branch to the master.
The system prompts a conflict. In this case, we only need to manually resolve the conflict and resubmit it.

 

14. branch management policies
1. Normally, if possible, Git uses the Fast forward mode. However, in this mode, branch information is lost after the branch is deleted.
2. If you want to forcibly disable the Fast forward mode, Git will generate a new commit at merge, so that the branch information can be seen from the branch history.
3. to disable this mode, you must add -- no-ff to the merge operation.
4. After merging $ git merge -- no-ff-m "merge with no-ff" dev, a new commit will be created. The-m parameter can be added here to provide a description.
5. After merging the preceding methods, we can view the branch history through $ git log -- graph -- pretty = oneline -- abbrev-commit.
Conclusion: When merging branches, you can use the -- no-ff parameter to merge them in normal mode. The merged branches have been merged in history, and we can see that they have been merged, however, fast forward merge cannot be seen as a merger.

 

15. Bug Branch
1. If you are currently developing on the dev branch, there is a bug that needs to be quickly resolved and merged to the master. In this case, you can create a new branch on the master (Named bug-101 ).
The content on dev cannot be submitted, so you need to store it through git stash. After storing it, you can view that the work zone is clean through git status.
2. If the bug is fixed on the master node, a temporary bug-101 branch will be created on the branch. After the fix is completed, the bug branch can be merged to the master node and deleted.
3. Go back to dev to continue development. You can view the work site through $ git stash list.
4. There are two ways to restore:
First, use git stash apply for recovery, but after recovery, the stash content is not deleted. You need to use git stash drop to delete it;
The second is to use git stash pop to restore and delete the stash content:
5. When the second method is used for recovery and the git stash list is executed, the storage work site cannot be found.
6. You can use the git stash list to view and restore the specified stash multiple times. Run the command $ git stash apply stash @ {0}

 

16. Feature Branch
Two points:
1. Develop a new feature. It is best to create a new branch.
2. If you want to discard a branch that has not been merged, you can use git branch-D <name> to forcibly delete it. (Note: Big D is used here)

 

17. Collaboration among multiple people
1. When you clone from a remote repository, Git automatically maps the local master branch to the remote master branch, and the default name of the remote repository is origin.
2. Use $ git remote to view the remote database information and check the current repository name (or use git remote-v to view details)
3. push branch $ git push origin <branch name> for example, $ git push origin master or $ git push origin dev
Note:
(1) The master branch is the master branch, so it must be synchronized from time to time remotely;
(2) The dev branch is a development branch. All members of the team need to work on it, so they also need to be remotely synchronized;
(3) The bug branch is only used to fix the bug locally, so there is no need to push it to the remote server unless the boss wants to check whether you have fixed several bugs every week;
(4) Whether the feature branch is pushed to a remote location depends on whether you work with your partner to develop it.
4. When other people clone the project by using the git clone command, the master branch is displayed by default (you can view it through git branch). If you want to develop it on the dev branch,
The dev branch of the remote origin must be created to the local device. Therefore, he uses this command to create the local dev branch: $ git checkout-B dev origin/dev,
Push to the remote device after the dev command is enabled. You only need $ git to push origin dev to submit the changes to the remote branch.
If a conflict occurs during push, pull is resolved to resolve the conflict and then pushed. If pull fails to be found because the local dev branch and remote origin/dev branch are not specified
No tracking information indicates there is no link). You can use git branch -- set-upstream branch-name origin/branch-name to set the link between dev and origin/dev.
After the final link is successful, pull again. If there is a conflict, resolve it, and push again.

 

Summary:

(1) view the remote database information and use git remote-v;

(2) If a new local branch is not pushed to a remote server, it is invisible to others;

(3) Use git to push origin branch-name from the local push branch. If the push fails, use git pull to capture remote New commits;

(4) Create the branch corresponding to the remote branch locally and use git checkout-B branch-name origin/branch-name. It is best to have the same name as the local branch;

(5) establish the association between the local branch and the remote branch, and use git branch -- set-upstream branch-name origin/branch-name;

(6) Capture branches remotely and use git pull. If there is a conflict, you must first handle the conflict.

 

 

18. Tag Management
1. When releasing a version, we usually create a tag in the version library to uniquely identify the version at the time of tagging. In the future, whenever a tag version is used,
Is to obtain the historical version of the time when the tag is created. Therefore, the tag is also a snapshot of the version library.
2. Although the Git tag is a snapshot of the version library, it actually points to a commit pointer (similar to the branch, right? But the branch can be moved, and the label cannot be moved,
Creating and deleting tags is completed instantly.

 

19. Create tags
1. Decide on which branch to package. For example, if you add a label on the master, you can directly use $ git tag v1.0 to mark the latest commit of the master branch as v1.0.
2. Run git tag to view all tags
3. the default tag is on the latest commit. If you want to bind the tag to a previous commit, you can use $ git tag v0.9 6224937, the following number indicates the password of the submission,
After the signature is complete, you can view the tag in git tag.
Note: When Using git tags, all tags are listed in alphabetical order instead of in chronological order.
4. view the tag information through git show <tagname>, for example, $ git show v0.9.
5. Create a label with instructions, $ git tag-a v0.1-m "version 0.1 released" 3628164 (use-a to specify the label name and-m to specify the description text)

 

20. Operation label
1. Delete tags: $ git tag-d <tagname>
2. push a tag to the remote: git push origin <tagname> or push all the tags not pushed to the remote local tag $ git push origin -- tags
3. if the tag has been pushed to a remote device and needs to be deleted, you need to take two steps: first, delete the local tag, and then delete the remote tag, that is, $ git tag-d v0.9 and $ git push origin: refs/tags/<tagname>

Git Official Website: http://git-scm.com

 

Related Article

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.