Common Git Tips

Source: Internet
Author: User

Common Git Tips
GuideGit is used by more and more companies, so we need to understand some of the skills in Git usage.

I. Configuration: Configuration

List all aliases and configurations

gitconfig--list

Git alias Configuration

gitconfig--globalalias.

Gitconfig -- globalalias. ststatus

Set git to case sensitive

git config --global core.ignorecase false
Ii. Help: Common auxiliary query commands

View everyday git in the git command line

git help everyday

Display common help commands of git

git help -g

Get Git Bash auto-completion

~/.git-completion.bash&&echo'[-f~/.git-completion.bash]&&.~/.git-completion.bash'>>~/.bashrc

Set automatic correction

gitconfig--globalhelp.autocorrect1
Iii. Remote: Remote repository Configuration

Obtain all remote reference configurations

gitremote

Or

gitremoteshow

Modify a remote address

gitremoteset-urloriginURL

Repo

View All unpackaged objects and disk usage in the current Warehouse

gitcount-objects--human-readable

Delete all inaccessible objects from the object database

gitgc--prune=now--aggressive
Iv. File Operations, Cache: Cache, Track: file tracking,

Display All tracked files

gitls-files-t

Show all untracked branches

gitls-files--others

Show all ignored files

gitls-files--others-i--exclude-standardgitcheck-ignore*gitstatus--ignored

Manipulation: Operation

Stops tracing a file but does not delete it.

gitrm--cached<file_path

Or

gitrm--cached-r<directory_path

Force Delete untracked files or directories

gitclean-fgitclean-f-dgitclean-df

Clear. gitignore

gitclean-X-f

Changes: Modify

Info: View information

View unsaved files after last submission

gitdiff

View the files for temporary changes to be submitted

gitdiff--cached

Show all saved and unsaved files

gitdiffHEAD

View the differences between the latest file version and Stage

gitdiff--staged

Dd: tracks a change and prepares to submit it.

Stage, not all

gitadd-p

Reset: Modify and Reset

Overwrite the modification of a local file with the latest content in the HEAD

gitcheckout--<file_name>

Stash: Storage

Info: View information

Display all saved Stashes

gitstashlist

Manipulation: Operation

Save: Save

Save the modification status of the file currently tracked without submitting it, and make the workspace clean up

gitstash

Or

gitstashsave

Save all file modifications, including untracked files

gitstashsave-u

Or

gitstashsave--include-untracked
Apply: Application

Apply any Stash without deleting it from the Stash list.

gitstashapply<stash@{n}>

Apply and delete the last Stash in the Stash list

gitstashpop

Or

gitstashapplystash@{0}&&gitstashdropstash@{0}

Delete all stored Stashes

gitstashclear

Or

gitstashdrop<stash@{n}>

Apply a single file from a Stash

gitcheckout<stash@{n}>--<file_path>

Or

gitcheckoutstash@{0}--<file_path>

Commit: Submit

Retrieve a submitted Hash Value

gitrev-list--reverseHEAD|head-1

Info: View information

List: Commit List

View all submissions since Fork Master

gitlog--no-merges--stat--reversemaster..

Displays all the commits in the current branch that have not been merged into the Master.

gitcherry-vmaster

Or

gitcherry-vmaster<branch-to-be-merged>

Visually view the entire Version tree

gitlog--pretty=oneline--graph--decorate--all

Or

gitk-all

View all submissions in branch 1 rather than Branch 2

gitlogBranch1^Branch2
Files: File Information

Displays the list of all files that are submitted until a certain time.

gitls-tree--name-only-r<commit-ish>

Displays all files modified in a certain submission.

gitdiff-tree--no-commit-id--name-only-r<commit-ish>

Displays all submitted modifications to a file.

gitlog--follow-p--<file_path>

Manipulation: operations on submission

Apply: Commit confirmation or application

Use cherry-pick to apply a cross-branch commit of a branch to another branch.

gitcheckout<branch-name>&&gitcherry-pick<commit-ish>

Ignore the Staging region during submission

gitcommit-am<commitmessage>

Ignore a file during submission

gitupdate-index--assume-unchangedChangelog;gitcommit-a;gitupdate-index--no-assume-unchangedChangelog

Revoking a deliberate ignoring

gitupdate-index--no-assume-unchanged<file_name>

Mark a submission as a Fixup for a previous submission

gitcommit--fixup<SHA-1>

Reset: resets the HEAD of the current branch to the status at a certain submission.

Reset HEAD to submit for the first time

gitupdate-ref-dHEAD

It is recommended that you only perform operations on the private branch after a Commit is discarded. Note: As with the previous operation, resetting does not change the current file status. Git will automatically list the Changes made to the current file and the Commit as Changes.

gitreset<commit-ish>

Undo & Revert: Undo and restore a Commit

Undo a submitter by creating a new submitter.

gitrevert<commit-ish>

Restore the status of a file to a Commit.

gitcheckout<commit-ish>--<file_path>

Update: modify a Commit.

Modify the information submitted last time

gitcommit-v--amend

Modify submitted author information

gitcommit--amend--author='AuthorName<email@address.com>'

After the global configuration changes, modify the author information.

gitcommit--amend--reset-author--no-edit

Modify the submission content of the previous Commit but do not modify the submission information

gitadd--all&&gitcommit--amend--no-edit

Branch: Branch

Info: View information

Obtain the current branch name

gitrev-parse--abbrev-refHEAD

Tag

List the most common labels on the current Branch

gitdescribe--tags--abbrev=0

List: branch Enumeration

Obtain all local and remote branches

gitbranch-a

Show only remote branches

gitbranch-r

Searches for all associated branches based on the Hash of a Commit.

Gitbranch-a -- contains <commit-ish> or gitbranch -- contains <commit-ish>

Changes: view Changes on a branch

View all modifications made in the past two weeks

Gitlog -- no-merges -- raw -- since = '2weeksago 'or gitwhatchanged -- since = '2weeksago'

Merger: View merging status

Traces the upstream branches of a branch.

gitbranch-uorigin/mybranch

List all branches and Their Upstream and last commit

gitbranch-vv

List all branches that have been merged into the Master

gitbranch--mergedmaster

Manipulation: Operation

Checkout: Detection and branch Switching

Quickly switch to the previous Branch

gitcheckout-

Checks out a branch without historical records

gitcheckout--orphan<branch_name>

Remove: Remove Branch

Delete local branch

gitbranch-d<local_branchname>

Delete remote Branch

Gitpushorigin -- delete <remote_branchname> or gitpushorigin: <remote_branchname>

Remove all branches that have been merged into the Master

gitbranch--mergedmaster|grep-v'^/*'|xargs-n1gitbranch-d

Remove all remote branches that have been deleted from the remote end.

Gitfetch-p or gitremotepruneorigin

Update: Information Update

Modify the current branch name

Gitbranch-m <new-branch-name> or gitbranch-m [<old-branch-name>] <new-branch-name>

Rchive: Packaging

Package Master branches

gitarchivemaster--format=zip--output=master.zip

Pack history records, including branch content, into a file

gitbundlecreate<file><branch-name>

Import from a Bundle

gitclonerepo.bundle<repo-dir>-b<branch-name>

Merge: Merge

Pull & Push: Remote branch merge operation

Use pull to overwrite local content

gitfetch--all&&gitreset--hardorigin/master

Pull a Pull request to the local branch based on the Pull ID

gitfetchoriginpull/<id>/head:<branch-name>

Or

gitpulloriginpull/<id>/head:<branch-name>

Rebase: change the base

Use the variable base to perform operations in Pull.

gitconfig--globalbranch.autosetuprebasealways

Change a feature branch to the master and then merge it into the master.

gitcheckoutfeature&&gitrebase@{-1}&&gitcheckout@{-2}&&gitmerge@{-1}

Automatically Stash all changes before changing the base

gitrebase--autostash

Automatic fixup submission and normal submission merging using the variable base

gitrebase-i--autosquash

Merge the first two commits using ReBase

gitrebase--interactiveHEAD~2

Diff & Conflict: Difference and Conflict

Info: View information

List all conflicting files

gitdiff--name-only--diff-filter=U

Open all conflicting files in the editor

gitdiff--name-only|uniq|xargs$EDITOR

Workflow: Workflow

SubModules: submodule

Info: View information

Manipulation: Operation

Add a Project to the Repo using the SubTree Method

gitsubtreeadd--prefix=<directory_name>/<project_name>--squashgit@github.com:<username>/<project_name>.gitmaster

Update all sub-modules

gitsubmoduleforeachgitpull

Work Tree

Manipulation: Operation

Create a new Working Tree from a repository

gitworktreeadd-b<branch-name><path><start-point>

Create a new Working Tree from the HEAD status

gitworktreeadd--detach<path>HEAD

From: http:// OS .51cto.com/art/201608/515536.htm

Address: http://www.linuxprobe.com/some-git-tips.html


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.