Common commands and tips for git

Source: Internet
Author: User
Tags git commands

Strong push, which uses your local code to replace content in your git repository with a strong overlay

Git push-f



git fetch--prune #这样就可在本地删除在远程不存在的branch

Mans Git-fetch

--prune

After fetching, remove any remote tracking branches which no longer exist on the remote.

-T,--tags

The most of the tags is fetched automatically as branch heads is downloaded, but tags it does not

Point at objects reachable from the branch heads that is being tracked is not being fetched by

This mechanism. This flag lets all tags and their associated objects is downloaded.

#另外, a few commands about Git branch

Git Branch # Querying for locally existing branch

Git branch-r # Querying for remote branch

Git branch-a # Querying local and remote branch

Git branch-d-r origin/todo #删除远程的todo Branch



Git tag-l | Xargs git tag-d #delete local tag (s)

git fetch VGT--prune #fetch from remote repo

#查询远程heads和tags的命令如下:

git Ls-remote--heads origin

git Ls-remote--tags origin

Git ls-remote origin





Git commit:

Git commit--amend undo last Commit


git push:

git push [remote-name] [master] push data to remote repository

Git push Origin: [Branch-name] Deletes the remote branch.


git diff:

git diff--name-only 73a79c 2d49d2 see the list of files that have been changed in the middle of two versions

Git diff:workspace and index file.

git diff head:workspace and Commint

git diff--cached:index file and commit


git fetch:

git fetch [Remote-name] retrieves all the commit information from the remote repository


git clone:

git clone [url] get the master branch of the remote repository


git log:

Git log-1 HEAD Displays the last commit message

Git log-p Displays the difference in content for each commit, and the parameter-num displays the most recent num commit variance

git log--stat only shows the count of increment rows.

Git reflog to view rest, checkout and other operational records. git log--pretty=oneline displays each commit message in one line.

Git log--pretty=fuller additional display submission date.

git log--since=2.weeks shows last two weeks of changes

git log--pretty=format: "%h-%an,%ar:%s"


Option description

%H full hash string for commit object (commit)

%h a short hash string for the Commit object

Full hash string for%T tree object

Short hash string for%t tree object

The full hash string of the parent object (%P)

%p a short hash string for the parent object

The name of the%an author (author)

%ae Author's e-mail address

%ad Author revision date (can be customized with-date= option)

%ar Author revision date, by how long before the way display

%CN the name of the submitter (committer)

%ce The submitter's e-mail address

%CD Date of submission

%CR submission date, as of how long ago the way it appears

%s Submission Instructions


git checkout:

Git checkout--<file> undo file changes

Git checkout-b branch-name Create and switch to the partition.


Git branch:

git breanch-d branch-name Delete a branch.

Git branch-d branch-name forcibly delete a branch.

Git merge Master merges the main branch into the current branch.


Git Remote:

Git remote to list the current project's long-range library

Git remote-v shows the clone address of the current project

git remote add [shortname] [url]

git remote show [remote-name] View the details of the repository

git remote [remote-old-name] [remote-new-name] modifying the repository name

Git remote RM [remote-name] Deleting a repository


git Reset:

git reset HEAD <file> undo files that have been staged (git add)


git reset--soft: revokes and rolls back the commit without affecting the index file, which location is specified by the last parameter. git reset--soft head^

git reset--hard: Undo Commit, Index file and workspace

git reset--mixed: Default option, revoke commit and index file, keep only workspace.

Git reset-: Deletes a file that is registered in the index file.


Git show-branch:

+ (plus sign) indicates that the branch contains the commit that this line identifies

(space) indicates that the branch does not contain a commit that is identified by this line

-(minus sign) indicates that the branch is in merge, and the contents of the row are the basic information of the merge.

* (asterisk) indicates that if you need to identify A + (plus sign) in a column and this column is the current branch, then the + (plus sign) is converted to * (asterisk).


Git:

Git GC shrink Space

Git count-objects-v View the size of the footprint.


Git recovers deleted files

Git to create a branch recovery file step:


Git branch [Recover-branch]

git checkout [Recover-branch]

git checkout Master

Git branch-d recover-branch


To view deleted files: Git ls-files–deleted

Recovery requires the new Checkout:git checkout–<deleted_file>

Simultaneous operation of multiple files can be done using Xargs

Git ls-fies-d | Xargs git Checkout--


git checkout-f recover deleted files


Ignore committing certain files or folders

1. Writing a file name or directory name within a. gitignore file ignores the commit, but only for files or directories that are not track-only, and is not valid for files that have been added to the version management.


2. Files or directories that have been added to the version management can be ignored using the following command:


git update-index--assume-unchanged PATH


Problems

1. Execute git remote add origin ... An error occurred: Fatal:remote origin already exists.

Execute the following command after git remote add origin ...:


Git remote RM origin




Git Stash:git also provides a stash feature that allows you to "store" your current work site and continue working after you resume the site

git stash List


The work site is still there, git put stash content somewhere, but need to restore, there are two ways:

One is to use git stash apply recovery, but after 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 Common operations Commands:

1) Remote Warehouse related commands

Checkout warehouse: $ git clone git://github.com/jquery/jquery.git

View remote repositories: $ git remote-v

Add remote repository: $ git remote add [name] [url]

Delete Remote repository: $ git remote RM [name]

Modify remote repository: $ git remote set-url--push [name] [Newurl]

Pull remote repository: $ git fetch [remotename] [Localbranchname]

Push remote repository: $ git push [remotename] [Localbranchname]

* If you want to submit a local branch test to the remote repository as the master branch of the remote repository, or as another branch called Test, as follows:

$git Push Origin Test:master//submit local Test branch as remote Master Branch

$git Push Origin test:test//submit local test branch as remote Test branch

2) Branch (branch) operation related commands

View local branch: $ git Branch

View Remote branch: $ git branch-r

Create local branch: $ git branch [name]----Note that the new branch will not automatically switch to the current branch after it is created

Switch Branch: $ git checkout [name]

Create a new branch and switch immediately to the new branch: $ git checkout-b [name]

Delete Branch: $ git branch-d [name]-----D option can only delete branches that have already joined the merge and cannot be deleted for branches that do not have a merge. If you want to forcibly delete a branch, you can use the-D option

Merge branch: git merge [name]----Merge the branch with the name [name] with the current branch

Create a remote branch (local branch push to remote): $ Git push origin [name]

Delete Remote branch: git push origin:heads/[name] or GIT push origin: [name]

* Create an empty branch: (Before executing the command remember to submit your current branch of the changes, otherwise it will be forced to delete the clean without regret)

$git symbolic-ref HEAD Refs/heads/[name]

$rm. Git/index

$git CLEAN-FDX

3) version (tag) operation related commands

View version: $ git tag

Create version: $ git tag [name]

Delete version: $ git tag-d [name]

View remote version: $ git tag-r

Create a remote version (local version push to remote): $ Git push origin [name]

Delete Remote version: $ git push origin:refs/tags/[name]

Merge the remote repository's tag to local: Git pull Origin--tags

Upload local tag to remote repository: $ Git push origin--tags

Create annotated tag:$ git tag-a [name]-M ' YourMessage '

4) Sub-module (submodule) Related Operations Command

Add sub-module: $ git submodule add [url] [path]

Example: $git submodule add Git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs

Initialize submodule: $ git submodule init----run only once when the warehouse is first checked out

Update submodule: git submodule update----need to run every time you update or switch branches

To delete a submodule: (4 steps away OH)

1) $ git RM--cached [path]

2) Edit the ". Gitmodules" file to delete the relevant configuration node of the Submodule

3) Edit the ". Git/config" file to delete the relevant configuration node of the Submodule

4) Manually delete the remaining sub-modules directory

5) Ignore some files, folders do not submit

Create a file with a name of ". Gitignore" under the repository root and write an unwanted folder name or file with one line per element, such as

Target

Bin

*.db

=====================

Common Git Commands

Git branch view all local branches

Git Status View current status

Git commit Commit

Git branch-a See all the branches

Git branch-r View all local branches

Git commit-am "Init" to submit and annotate

git remote add origin [email protected]:ndshow

Git push origin master pushes files to the server

Git remote show origin shows the resources in origin

Git push Origin Master:develop

Git push Origin Master:hb-dev associate a local library with a library on the server

git checkout--track origin/dev switch to remote Dev branch

git branch-d master Develop delete local library develop

git checkout-b Dev builds a new local branch dev

Git merge origin/dev Merge branch dev with current branch

git checkout dev switch to local dev branch

Git remote show to view the long-range library

git Add.

git RM file name (including path) removes the specified file from git

git clone git://github.com/schacon/grit.git pull the code down from the server

git config--list See all users

Git ls-files look at the already committed

git rm [file name] Delete a file

Git commit-a commits all changes to the current repos

git add [file name] Add a file to git index

Git commit-v you can see the difference in commit when you use the-v argument

Git commit-m "This is the message describing the commit" adds a commit message

Git Commit-a-A represents add, adds all the change to git index and then commits

Git commit-a-V General commit command

git log to see your commit logs

git diff view updates that have not yet been staged

git rm a.a Remove files (removed from staging area and workspaces)

git rm--cached a.a Remove Files (removed from staging area only)

Git commit-m "Remove" Remove files (removed from git)

Git rm-f a.a forcibly remove modified files (removed from staging area and workspaces)

git diff--cached or git diff--staged view the updates that have not yet been submitted

Git stash push to push files to a temporary space

Git stash pop to pop files from scratch space

git stash List

---------------------------------------------------------

git remote add origin [email protected]:username/hello-world.git

Git push Origin master submits a local project to the server

-----------------------------------------------------------

Git pull local and server-side synchronization

-----------------------------------------------------------------

git push (remote warehouse name) (branch name) pushes the local branch to the server.

Git push Origin Serverfix:awesomebranch

------------------------------------------------------------------

Git fetch is equivalent to getting the latest version from remote to local, not automatically merge

Git commit-a-M "Log_message" (-A is to commit all changes,-M is to add log information) local modifications are synchronized to the server side:

Git branch branch_0.1 master creates branch_0.1 branch from Master Branch Master

git branch-m branch_0.1 branch_1.0 rename branch_0.1 to branch_1.0

git checkout branch_1.0/master switch to Branch_1.0/master branch

Du-hs




Do not use git pull to replace it with git fetch and git merge



Git rebase is used to merge changes from one branch into the current branch


In the process of rebase, there may be conflicts (conflict). In this case, Git will stop rebase and will let you resolve the conflict, after resolving the conflict, use the "git-add" command to update the index of these content, then you do not need to execute git-commit, as long as the execution:

$ git rebase--continue

This way git will continue to apply the remaining patches.

At any time, you can use the--abort parameter to terminate the action of Rebase, and the "MyWork" branch will return to the state before the start of rebase.

$ git rebase--abort


This article is from the "Resource Sharing" blog, so be sure to keep this source http://liuliheng.blog.51cto.com/7948095/1687666

Common commands and tips for git

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.