Linux training tutorials using git under Linux

Source: Internet
Author: User
Tags tag name using git git clone

Linux Training Tutorial Git's use under Linux

* Initialize git repository, use git init command

* Add files to git repository in two steps:

1, use git add filename, can be used several times, add multiple files to staging area

2 , using git commit-m "description"; Complete commit to Branch

Brother even Linux training tutorial git use under Linux

* View workspace status, use the git status command, and use git diff filename to view changes if prompted for changes

*head points to the current version, head^ represents the previous version, head^^ on the previous version ... Head~100 points to the previous version of 100th.

* Fallback version: Use git log to view the commit history; use Gitlog--pretty=oneline to refine the display

Use git reset--hardcommit_id to fallback to version number commit_id

* After fallback version, if you want to change back, you can use Git reflog to view the history command, find the version number you want to change back, and then use Git Resethard commit_id to return.

* Note: git tracks and manages changes, not files, and if a file is modified and added after it is modified again, it will only commit the first modification if it is not submitted again.

* Undo Changes:

1, if the file is still in the work area, that is no add and no commit, then use gitcheckout-filename to restore to the server version;

2, if already add to staging area, first use git reset HEAD filename to retrieve the workspace from staging area, and then follow 1 to operate;

3, if it has been submitted to the repository, the version of the fallback way to modify it;

4, if you have been push to the remote warehouse, it is troublesome

* Delete using the following command:

1. GITRM filename removed from workspace

2. Gitcommit-m "description" to update the files in the branch to delete

After the file in the workspace is deleted, you can use gitcheckout-filename to retrieve it from the branch, but only restore the file to the latest version, and the changes after the last commit cannot be restored.

Branch

1. Create a branch

Git checkout-b branchname Create and switch to a partition, equivalent to two commands:

Git branch branchname Create a branch

git checkout branchname switch to partition

2. View the branch that is currently pointing: Git branch Lists all the branches, and the branch that is currently pointing to has more than one *

3, Switch branch is git checkout branchname

4. Merge branch: git merge branchname merge branchname to current branch

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

Note: creating, merging, and deleting branches is fast, and git encourages the use of branching to accomplish a task, deleting the branch after merging, and working directly on the master branch, but the process is more secure; These are fast because in these processes we just modify the pointer to the branch, such as creating a branch that creates a pointer to the branch, and then modifies the head to point to the pointer, that is, the head points to the branch, and the branch is the commit.

* Conflict Resolution: When Git cannot automatically merge branches, it must resolve the conflict first, after resolving the conflict, and then committing, completing the merge

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

* Save work site Git stash save to do other work without affecting the last modification

Resume work site: 1, git stash apply restore does not delete content in stash

2, Gitstash pop recovery will delete the contents of stash

* Remote Library information production see Using Git remote (-V) plus-v display information more detailed

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

Git push origin (remote library name) master (the 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, use git pull to merge first

3. If there is a conflict in the merge, resolve the conflict, submit it locally

4, re-push

Note: If you are prompted for "No tracking information" when using git pull merge, the local branch does not establish a link relationship with the remote branch and establishes the relationship using the following directive: Git branch--set-upstream branch origin/ Branchname

* Locally created branch corresponding to remote: Git branch-b branchname origin/branchname the name of the local and remote branch is best consistent

* Create tags

1, hit the tag git tag name default tag hit on the latest commit, if you want to hit the other version, find commit_id can

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

git tag tag_name commit_id

3. View Tags: git tag shows all tags

4. View tag information: Git show tag_name

5. Create a tag with description: Git tag-a tag_name-m "info";-A For tag name,-M to specify descriptive text

* Action tag: git tag-d tag_name delete tag

Push tags to remote library: git push origintag_name

Push all tags at once to the remote library: git pushorigin--tag


Linux training tutorials using git under Linux

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.