Git Common Commands Summary

Source: Internet
Author: User
Tags git mergetool

git initCreate a new repo locally, enter a project directory, execute git init, initialize a repo, and a. git folder under the current folder. git cloneGet a URL for the remote git repo, and create a local copy.     The general format is git clone [url]. Clone down repo will be named after the last slash of the URL, create a folder, if you want to specify a specific name, you can git clone [url] newname specified. git statusQueries the status of Repo. Git status-s:-s means short, the-s output tag will have two columns, the first column is for the staging region, the second column is for the working directory. git log     show Commit history of a branch.     git log--oneline--number: Each log displays only one row, showing the number bar. & nbsp    git Log--oneline--graph: Can graphically represent a branching merge history .     git log branchname can display log.    for a specific branch  git log--oneline branch1 ^branch2, you can view the commit in branch 1, but not in branch 2. ^ means exclude this branch (you might want to add quotes to ^branch2 under window) .      git log--decorate will display the tag information .     git log--author=[author name] can specify the author's commit history .     git log--s Ince--before--until--after filter log.     --no-merges based on submission time you can exclude the commits of the merge .     git Log--grep filter log:git log--grep=keywords      By default, git log--grep--author is the or relationship, that is, satisfies a bar that is returned if you Want them to be and relationships, plus--all-match's option.     git log-s: Filter by introduced diff.      For example: Git l Og-smethodname (Note that there is no equal sign between S and later words) .     git log-p: Show patch introduced at each commit.    &nbs p; Each commit is a snapshot (snapshot), and git puts eachSubmitted diff calculated as a patch show to you see .      Another way is git show [sha].     git log--stat:show diffstat of C Hanges introduced at each commit.      is also used to look at the relative information of the changes,--stat is simpler than the-p output .     git addBefore committing, Git has a staging area (staging area) that can be placed in a newly added file or added new changes.     The commit change is the last change that was added to the staging area, not the change on our disk.     git Add. All files in the current working directory are added recursively. git diff      non-parametric git diff:     show diff of Unstaged changes.      This command compares the differences between the current file in the working directory and the snapshot of the staging area, i.e. changes that have not been staged since the modification .       To see the difference between a file that has been staged and the snapshot that was last committed, you can use:      git diff--cached Command .     show diff of Staged changes.      (Git 1.6.1 and later versions also allow Git diff--staged, the effect is the same) .      git diff head     show diff of all staged or unstated changes.      also compare Woking Director All changes between Y and last commit .       If you want to see what has changed since a certain version, you can use:     git diff [version tag]      As with the log command, diff can also be added with the--stat parameter to simplify the output .      git diff [Brancha] [BRANCHB] can be used to compare two branches .       It actually returns a patch from A to B, not the result we want .      generally we want the result is two branches apart after the individual changes are what, is by the command :     git diff [Brancha] ... [BRANCHB] gives the .      Actually it is: Git diff $ (git merge-base [bRancha] [BRANCHB]) [BRANCHB] Results .   git commitSubmit the changes that have been added. Git commit-m "The commit message" Git commit-a will first add all the changes that have been made to the track file and submit it (a bit like an SVN commit without first staging).     For files without track, git add is still required. git commit--amend supplemental commit. A new commit is made using the same parent node as the current commit node, and the old commit will be canceled. git reset     undo changes and commits.      The head keyword here refers to the latest commit at the very top of the current branch. That is, the latest version on that branch in the repository .  & nbsp  git reset head:unstage files from index and reset pointer to head      This command is used to remove accidentally add files from the staged state , you can work on a single file individually: Git reset HEAD--filename, this--can also be .     git reset--soft     move HEAD To specific commit reference, index and staging is untouched.     git reset--hard     uns Tage files and undo any changes in the working directory since last commit.      use git reset-hard head for Res ET, after the last commit, all staged changes and changes to the working directory will disappear and revert to the last submitted state .      The head here can be written to any submitted sha-1.      git reset without soft and hard parameters, actually with default parameters mixed.       Summary:    &NBSP;GIT reset--mixed ID, is to change the head of Git (that is, the commit record has changed), but the file has not changed (that is, the working tree has not changed). The contents of commit and add are canceled.      git reset--soft ID. In fact, it's Git reset–mixed ID, and then git add again.The content of the commit is eliminated.      git Reset--hard ID. Is the git head changed, the file is changed .      Sort by the scope of the changes as follows:      soft (Commit) < mixed (commit + Add) < hard (commit + add + local working)   git revertReverses the undo commit. Simply pass the name of the error commit (reference) as a parameter to the command.     git revert HEAD: Undo the most recent commit. Git revert creates a new, reverse commit that you can tell git not to commit by using parameter-N. git rmgit rm file: Removes files from the staging zone and also removes the working directory.     git rm--cached: Removes files from the staging area, but stays in the working directory. git rm--cached is functionally equivalent to git reset HEAD, which clears the cache but does not move the working directory tree. git cleanGit clean removes files without track from the working directory. The usual argument is git clean-df:-D means to remove the directory at the same time,-F for force, because in the git configuration file, clean.requireforce=true, if not added-f,clean will refuse to execute. git mvGit rm--Cached orig; MV Orig New; git Add new git stashPress the current change into a stack.     Git stash will push all changes in the current directory and index (but not the non-track files) into a stack and leave you with a clean working state, which is at the last commit.     The Git Stash list displays the list for this stack.     Git stash apply: Take out the previous item in the Stash ([email protected]{0}) and apply it to the current working directory.     You can also specify other items, such as git stash apply [email protected]{1}.     If you want to delete an item in stash while you're applying it, you can use Git stash pop to delete items from the stash: Git stash drop: Delete the previous, or specify a parameter to delete the specified item. Git stash clear: Delete all items. git branchGit branch can be used to list branches, create branches, and delete branches.     Git branch-v can see the last commit of each branch.     GIT branch: Lists all branches locally, and the current branch is marked with an asterisk.      Git branch (branchname): Create a new branch (when you create a branch in this way, the branch is based on your last commit).     Git branch-d (branchname): Deletes a branch.     Delete Remote branch: git push (remote-name):(branch-name): Delete a remote branch. This is because the complete command form is: git push remote-name local-branch:remote-branch and the part of Local-branch here is empty, which means to delete the Remote-branch git checkoutgit Checkout (branchname)

switch to a branch.Git checkout-b (branchname): Create and switch to a new branch.     This command is the result of a combination of Git branch newbranch and git checkout newbranch.     Checkout has another role: replace local changes: git checkout--<filename> This command replaces the files in your working directory with the latest content in the head. Changes that have been added to the staging area and new files are not affected. NOTE: git checkout filename Removes all changes that are not staged and committed in the file, and the operation is irreversible. git mergeMerge a branch into the current branch.      git merge [Alias]/[branch] merges the remote branch into the current branch.     If there is a conflict, you need to modify it manually, you can use Git mergetool. When resolving conflicts, Git diff can be used, and after the fix is added with git add, that means the conflict has been resolved. git tagTag a point in the history as import.     will create a permanent bookmark on a commit, usually by releasing a release version or by adding a tag after the ship has something.     For example: git tag v1.0 git tag-a v1.0, the-a parameter will allow you to add some information that makes an annotated tag.          When you run the git tag-a command, Git opens an editor to let you enter the tag information.     We can use commit sha to give a past commit to hit Tag:git tag-a v0.9 XXXX Push when it is not included, if you want to include, you can add--tags parameters when push. When fetch, branch head can reach the tags are automatically fetch down, tags that aren ' t reachable from branch heads would be skipped. If you want to make sure that all tags are Included, you need to add the--tags option. git remoteList, add and delete remote repository aliases.     Because you don't need to use the full URL every time, Git creates an alias for each remote repo URL, and then uses GIT remote to manage the list.     Git remote: Lists the remote aliases.     If you clone a project,git will automatically add the original URL, alias is called: Origin.     Git remote-v: You can see the actual URL corresponding to each alias.     git remote add [alias] [url]: Add a new remote repo.     git remote rm [alias]: Delete an existing remote alias.     git remote rename [Old-alias] [New-alias]: rename. git remote set-url [alias] [url]: Update URL. You can add the-push and fetch parameters to a different access address for the same alias set. git fetchDownload new branches and data from a remote repository. You can git fetch [alias] fetch a remote repo, or git fetch--all fetch all repo fetch will fetch all the data that you do not have locally, all the branches taken down can be called the remote branches, they are the same as the local branch ( You can see Diff,log, etc., or merge to other branches), but Git doesn't allow you to checkout them. git PullFetch from a remote repo and try to merge into the current branch.         The pull = = fetch + Merge Fetch_head git pull executes the git fetch first, then executes the git merge and merges the HEAD of the branch into the current branch. This merge operation will produce a new commit. If you use the--rebase parameter, it executes git rebase instead of the original git merge. git rebase--rebase does not produce a merged commit, it will temporarily save all commits locally as patches, put them in the ". Git/rebase" directory, update the current branch to the newest branch tip, and finally apply the saved patches to the branch.     Rebase in the process, there may be conflicts, Git will stop rebase and let you resolve the conflict, after resolving the conflict, with git add to update the content, and then do not have to commit, just need: Git rebase--continue will continue to play the remaining patches. Git rebase--abort will terminate rebase, and the current branch will return to the state before rebase. git pushPush your new branches and data to a remote repository.     git push [alias] [branch] will merge the current branch into the [branch] branch on alias. If the branch already exists, it will be updated and will be added if it does not exist. If multiple people are to the same remote repo push code, GIT will first run git log on the branch you're trying to push, checking to see if the server's branch now tip is visible in its history, and if it's not seen in the local history, If the local code is not up-to-date, Git will reject your push, letting you fetch,merge and then push, so that everyone's changes will be taken into account. git reflogGit reflog is a command to manage Reflog, and Reflog is a mechanism that GIT uses to record changes to a reference, such as a change in branch or head reference.     When Git reflog does not specify a reference, the Reflog of the head is listed by default. [Email protected]     {0} represents the current value of the head, and [email protected]{3} represents the value before the head changes 3 times. Git logs changes to the Reflog file in the HEAD, with a path of. Git/logs/head, and the Reflog files for the branch are placed in subdirectories under the. Git/logs/refs directory. Special Symbols:^ Represents the parent commit, when a commit has multiple parent commits, it is possible to represent the first few parent commits by following a number in the ^: ^ equivalent to ^1. ~<n> equivalent to a continuous <n> ^.

Git Common Commands Summary

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.