Git is used in linux and Gitlinux

Source: Internet
Author: User

Git is used in linux and Gitlinux

* Initialize the git repository and use the git init command


* Add a file to the git repository in two steps:

1. Use git add filename. You can use it multiple times and add multiple files to the temporary storage area.

2. Use git commit-m "Description" to complete the submission to the Branch


* View the workspace status and run the git status Command. If a prompt is displayed, use git diff filename to view the modification content.


* HEAD points to the current version. HEAD ^ indicates the previous version, and HEAD ^ indicates the previous version ...... HEAD ~ 100 points to the previous 100th versions.


* Version rollback: Use git log to view the submission history. Use git log -- pretty = oneline to simplify the display.

Use git reset -- hard commit_id to roll back to the version with the version of commit_id.


* If you want to change the version back after rolling back the version, you can use the git reflog command to view the history command, find the version number you want to change back, and then use git reset hard commit_id to return it.


* Note: git tracks and manages modifications instead of files. If a file is modified and added, it is modified again. If it is not added again, only the first modification is submitted.


* Undo modification:

1. If the file is still in the workspace, that is, there is no add or commit, use git checkout -- filename to restore it to the server version;

2. If you have already added it to the temporary storage area, use git reset HEAD filename to retrieve the workspace from the temporary storage area, and then follow 1 to perform the operation;

3. if the version has been submitted to the version library, modify the version based on the version rollback method;

4. If it has been pushed to the remote warehouse, it will be troublesome.


* Run the following command to delete a file:

1. Delete git rm filename from Workspace

2. git commit-m indicates that files in the update branch are deleted.

After deleting a file in the workspace, you can use git checkout -- filename to retrieve the file from the branch. However, you can only restore the file to the latest version. Modifications made after the last commit cannot be restored.


* Branch:

1. Create a branch

Git checkout-B branchname:

Git branch branchname: Create a branch

Switch git checkout branchname to partition

2. view the branches currently pointed to: git branch will list all branches. The branches currently pointed to are added *

3. Switch the branch to git checkout branchname.

4. merge branch: git merge branchname to the current Branch

5. Delete branch: git branch-d branchname Delete branchname branch

Note: The process of creating, merging, and deleting branches is very fast. git encourages you to use branches to complete a task and delete branches after merging, which is the same effect as directly working on the master branch, but the process is safer. The reason for this is that in these processes, we only modify the pointer to the branch. For example, if we create a branch, we create a pointer to the branch, then modify the HEAD to point to this pointer; that is, the HEAD points to the branch, and the branch is to submit.


* Conflict Resolution: If git cannot automatically merge branches, the conflict must be resolved first. After the conflict is resolved, the merge is completed.

Use git log -- graph to view the branch merge graph.


* Save the work site git stash. After saving, you can perform other work without affecting the last modification.

Recovery site: 1. The content in stash is not deleted when git stash apply is restored.

2. When git stash pop is restored, content in stash will be deleted.


* For details about remote database information production, use git remote (-v) and add-v to display more details.


* Branch push to remote database: Push all local submissions to remote database

Git push origin (remote database name) master (branch to be pushed)


* Crawling branch: git pull; git clone


* Collaboration mode:

1. Use git to push origin branchname to push your own changes

2. If the push fails because the remote branch/branch ratio is updated locally, use git pull to merge

3. If a merge conflict exists, resolve the conflict and submit it locally.

4. Push again

Note: If the "no tracking information" prompt is displayed when you use git pull to merge, the local branch does not establish a link with the remote branch. Use the following command to establish a link: git branch -- set-upstream branch origin/branchname


* Create a local branch that corresponds to the remote branch: git branch-B branchname origin/branchname. The local branch name should be the same as the remote branch name.


* Create a tag

1. tag git tag name. The default tag is on the latest committed commit. If you want to append it to another version, find commit_id.

2. Display tags: git log-pretty = oneline -- abbrev-commit

Git tag tag_name commit_id

3. View tags: git tags display all tags

4. view the tag information: git show tag_name

5. Create a label with the description: git tag-a tag_name-m "information";-a indicates the tag name, and-m indicates the description text.


* Operation tag: git tag-d tag_name Delete tag

Push tags to a remote database: git push origin tag_name

Push all tags to the remote database at a time: git push origin -- tag



How to access the Git environment configured in Linux

Git clone IP:/git-path
Access through ssh by default
 
Git version control tools are generally used to download the latest Linux kernel. How can I use git to download the old Linux kernel?

Git not only obtains "latest" code, but also historical code. You can use git log, git tag, git branch-a, and other commands to view the historical information and tag information of the kernel code (corresponding labels should be applied to different official versions ), branch information. You can use the git checkout xxx command to switch to the xxx version.

Obviously, you should first learn about git usage ......

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.