Summary of common commands for GIT operations

Source: Internet
Author: User
Tags diff
Summary of COMMON commands

One, fallback to a node, by the following command:

Git Reset–hard HASH returns to a node without preserving modifications such as:

Git Reset–hard HASH returns to a node, preserving the modification.

Second, all the local changes. No commits are returned to the original state.

Git Checkout.

git checkout repository means switch repository like git checkout dev switch to dev repository

The git checkout file address means that the file has been modified, such as Git checkout Backend/controller/site

Third, review the submission log

Git Log

Iv. Viewing branches

Git Branch without parameters: Lists the local branch, with an * number in front of the current branch

V. Handling LF Problems

The problem arises because of inconsistencies in window and Linux spaces and newline conversions, and is handled as follows:

Configure global Variables git config--global core.autocrlf false

View global variables git config–global–l to view global variables

mkdir learngit//Create a folder

CD learngit//Toggle Current Directory

PWD//Displays the full path of the current directory

GIT init/Initialize directory

Ls-ah//Display all files in the current directory, including hidden files

Cd.>readme.txt//Create an empty file

git add readme.txt//adding files to the Git repository

Git commit-m "wrote a Readme file"//Submit files, plus change notes

git status//view current repository file churn status

git diff//is a comparison of workspaces (work Dict) and staging Area (stage)

git diff--cached//is a comparison of staging area (stage) and branch (master)

After modifying the contents of the file, git status will prompt the use "git add" and/or "Git commit-a" note that after the add commit, you cannot commit directly

git log//view Git commit record, including details such as time and submitter.

git log--pretty=oneline//view version number and submission instructions only

git reset--hard head^//Rollback last version

git reset--hard head^^//Rollback on the first version

git reset--hard head~100//rollback TOP 100 versions

git reset--soft HEAD//fallback without resetting buffers and workspaces

git reset--mixed in HEAD//fallback, default option

git reset--hard HEAD//fallback reset buffers and workspaces

git reset//Do not specify head to empty the cache changes

git reset filename//Empty buffer modify the specified file

git reset--hard//Don't specify head to empty workspace and cache changes

git reset--hard filename//Empty workspace and buffer specify file modification

Cat Readme.txt//view file contents

If you want to withdraw after rollback, there are two ways

1) need not close the original terminal window, retrieve the latest version number, enter the previous number, for example

git reset--hard ec6980a

2) Close the terminal window, reopen it, enter Git reflog, view each record of the operation, retrieve the version number rollback

Git checkout--File//Undo workspace operation, there are two cases, 1、 not added to the buffer zone, is to undo the local workspace modification, 2、 has been added buffer, is to undo the cache after the modification, restore the cached version

Git checkout--in the file command--very important, not--becomes the "switch to another branch" command

git checkout branch//Toggle branch, while resetting the buffers and workspaces, if the workspace has been modified without committing, you need to commit or stash

git checkout branch--force//Toggle Branch While resetting buffers and workspaces

git checkout--force//Do not specify branch, used to clear the workspace changes (the buffer is unchanged, if there was an add, then the workspace is consistent with the buffer zone)

git reset HEAD fileName//Can undo staging area's changes (unstage)

RM test.txt//File Manager Delete files, note Local Delete to correspond with warehouse

git rm text.txt//Delete remote repository file and commit git commit

Git checkout-test.txt//Assuming the local RM mistakenly deleted the file, you can use the instructions from the repository to copy the latest to local, with the version of the repository to replace the version of the workspace, regardless of whether the workspace is modified or deleted, can be "one-click Restore"

Ssh-keygen-t rsa-c "liwenxin@foreveross.com"//Set up the local associated account information, all the way to enter, do not set a password directly empty.

Open ~/.ssh//mac opening the home directory for SSH

CD ~/.SSH//If the previous steps accidentally entered a password, you can reset it to a blank password in the following way

Ssh-keygen-p-F Id_rsa//Enter the old password two times as required new password

Git remote Add origin git@github.com:gz-jam/learngit.git//replace with your own GitHub account name, local associated remotely library

GIT remote RM origin//If the association is wrong or needs to be re-bound

Git remote Add origin git@github.com:michaelliao/learngit.git//can be re-bound

Git push-u origin master//local library of all content pushed to the remote library, enter Yes to confirm, the current branch master is pushed to remote, because the remote library is empty, we first push the master branch, with the-u parameter, Git will not only push the local master branch content to the remote new Master branch, but also the local master branch and the Remote Master Branch Association, in the future push or pull to simplify the command.

Git push Origin master//second start can be used without-u

git clone git@github.com:michaelliao/gitskills.git//Clone remote repository, GIT supports a variety of protocols, the default git://use SSH, but can also use other protocols such as HTTPS. such as Https://github.com/gz-jam/gitskills.git

git checkout-b dev//Create branch and switch current branch to dev, equivalent to executing two instructions such as Git branch dev and git checkout dev

Git branch//View all branches of the current project, preceded by * represents the currently active branch

git merge dev//used to merge the specified branch to the current branch

git branch-d dev//merge to consider deleting redundant project branches

git branch-d dev//Branch submit file not merged, if delete will prompt not merged, whether to forcibly delete note capital D

Git cannot perform a "quick merge" when both branches have submissions in the same file, and Git status,git is needed first <<<<<<<,=======,>>>>> >> mark out the contents of different branches, then re-git add file after adjusting, then git commit file can resolve the conflict

git log--graph--pretty=oneline--abbrev-commit//You can see the merge of the branches

git log--graph//This command can also see the branch merge diagram

Git merge--no-ff-m "merge with No-ff" dev//Disable Fast forward mode, GIT will generate a new commit at merge

Git stash//The current branch work is not completed but do not want to submit the warehouse, can be saved with instructions, ensure that switching other branches will not cause code loss

git stash list//view stash content, there are two ways to recover, one is to use git stash apply stash@{0} recovery, but after the recovery, stash content is not deleted, you need to use git stash drop to delete, another way is to use Git Stash pop, restore the stash content also deleted

git remote//view information

Git remote-v//display more detailed information

Git push origin master//Push branch, which is to push all local commits on that branch to the remote library, to specify a local branch when pushing

Locally created branches are not visible to others if they are not pushed to remote

Push branches from the local, use GIT push Origin branch-name

git checkout-b dev origin/dev//Create remote Origin's dev branch to local, default branch master

git push//conflict occurs when GIT pull replaces code

Git pull//If it fails, it prompts "No tracking information" because there may not be a link between the local dev branch and the remote Origin/dev branch.

Git branch--set-upstream-to=origin/dev dev//set links to Dev and origin/dev

Merge conflicts, need to be resolved manually, workaround as previously mentioned, git status, then manually fix, then git add and git commit, and finally git push

git tag v1.0//commit is too long to remember, can be labeled on the branch

git tag v0.9 6224937//Tag The specified commit number on the branch

Labels are not listed chronologically, but are sorted alphabetically. You can use Git show <tagname> to view tag information

such as Git show v0.9

git tag-a v0.1-m "version 0.1 released" 3628164//Create label with description, specify label name with-A,-m to specify descriptive text

git tag-d v0.1//tag is wrong or can be deleted

The created labels are stored locally only and are not automatically pushed to the remote. If you want to push a tag to a remote, use the command GIT push Origin <tagname>

Example: Git push Origin v1.0

Or, all-in-one push is not yet pushed to a remote local label

Example: Git push Origin--tags

If the label has been pushed to the remote, to remove the remote label is a bit troublesome, first removed from the local, git tag-d v0.9, and then removed from the remote. The Delete command is also push, but the format is as follows for git push origin:refs/tags/v0.9 or Git push origin--delete tag v0.9

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.