How to use Git

  
under Linux

Git is an open source distributed version control system that can help Linux manage kernel development. How does Linux use Git? The following small series will introduce you to the method of using Git for Linux. Interested friends may wish to understand.

* initialize git repository, use git init command

* Add files to git repository in two steps:

1, use git add filename; can be divided into more than Use, add multiple files to the staging area

2. Use git commit -m “description>;Complete commit to branch

*View workspace status, use git status command If prompted to modify, use git diff filename to view the changes

*HEAD points to the current version, HEAD^ indicates the previous version, HEAD^^ previous version ……HEAD~100 points to the previous 100th Versions.

*Backup version: Use git log to view the commit history; use git log --pretty=oneline to reduce the display

Use git reset --hard commit_id to fall back to the version with the version number commit_id

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

*Note: git tracks and manages changes, not files. If a file is modified and added, it will be modified again. If you do not add it again, only the first modification will be submitted.

*Undo changes:

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

2, if you have added to the temporary storage area, first use git reset HEAD filename to retrieve the work area from the temporary storage area, and then follow the operation of 1;

3, if submitted to the repository, Then you can modify it according to the version rollback method.

4. If you have already pushed to the remote repository, you are in trouble

*Delete using the following command:

Git rm filename Remove from the workspace

2, git commit -m ” Description “ Update the files in the branch for deletion

After deleting the files in the workspace, you can use git checkout - - filename is retrieved from the branch, but only the files can be restored to the latest version, and the modifications after the last commit cannot be recovered.

*Branch:

1. Create a branch

git checkout -b branchname Create and switch to a partition, which is equivalent to the following two commands:

Git branch branchname Create branch

git checkout branchname Switch to partition

2. View the branch that is currently pointing: git branch will list all branches, the current branch is more than one *

3, switch branch is git checkout branchname

4, merge branch: git merge branchname merge branchname to the current branch

5, delete branch: git branch -d branchname delete branchname branch

Note: Creating, merging, and deleting branches are very fast. git encourages the use of branches to complete a task. Deleting a branch after merging is the same as working directly on the master branch, but the process is more secure. These are faster because in these processes we just modified the pointer to the branch, such as creating a branch is to create a pointer to the branch, and then modify the HEAD point The pointer; that is, HEAD points to the branch, and the branch is the commit.

* Conflict resolution: When git can't merge branches automatically, you must first resolve the conflict; after resolving the conflict, commit again, that is, the merge is completed

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

*Save the job site git stash save and then do other work without affecting the last modification

Restore the work site: 1, git stash apply restore does not delete the contents of stash < Br>

2, git stash pop will delete the contents of stash when restoring

*Remote library information production using git remote (-v) plus -v display information in more detail

* Branch push to remote library: push all local commits to remote library

git push origin (remote library name) master (branch to push)

*crawl branch: git Pull ; git clone

*Collaboration mode:

1. Push your own changes using git push origin branchname

2. If the push fails, because the remote branch is newer than the local one, First use git pull to merge

3, if the merge conflicts, resolve the conflict, submit locally

4, then push

Note: If you use git pull to merge prompts & rdquo ;no tracking information“ indicates that the local branch does not To establish a link with the remote branch, use the following command to establish the relationship: git branch --set -upstream branch origin/branchname

*Create a branch corresponding to the remote locally: git branch -b branchname origin/branchname Local and The name of the remote branch is the same as

*Create the tag

1. Mark the git tag name The default tag is on the latest commit. If you want to hit other versions, find the commit_id.

2, display label: git log -pretty=oneline --abbrev -commit

git tag tag_name commit_id

3, view the label: git tag display all tags < Br>

4, view the tag information: git show tag_name

5, create a label with instructions: git tag -a tag_name -m ” information "ld"; -a indicates the tag name, -m Specify Description Text

*Action Tag: git tag -d tag_name Delete Tag

Push Tag to Remote Library: git push origin tag_name

Push all tags to the remote library at once: Git push origin --tag

The above is the introduction of Linux using Git. This article introduces the use of git init command, git delete, branch creation and deletion, etc. I hope you have a better understanding of the use of git.

Copyright © Windows knowledge All Rights Reserved