Summary of common commands in git and some problems thinking

Source: Internet
Author: User
Tags commit diff reset git clone

Thanks to Liaoche, the great God shared git lessons

Master the following commands, basically daily enough local warehouse common operation to create a repository

Git init Add file to buffer

Git add file to warehouse

Git commit-m "Commint describtion" undo Modify or clear buffer

git reset/git reset HEAD file Discard or undo changes

Git checkout--file Delete

git rm file
Equivalent to git rm after git add undo Delete Operation

git reset
git checkout--file view specified file

Git cat file comparison workspace vs. repository

git diff View Log

git log operation history

git reflog version fallback

git reset--hard Commit-id

or git reset--hard head-id equivalent to specifying the current HEAD to the specified version created and pointing to the branch

git checkout-b <branch> switch Branches

git checkout <branch> View branch Information

Git branch
More information about git branch-v merging the specified branch to the current branch

git merge <branch> normal mode merging, preserving branch information

git merge--no-ff-m "" <branch> This information will remove the branch from the remote display

git branch-d <branch> temporary Save workspace site

Git stash lists the workspace site

Git list deletes the site and restores the workspace

Git stash pop Add the current workspace all files to the buffer zone

git Add. Test Connection

SSH-T git@github.com remote libraries related to local libraries add a remote version library

Git remote add origin git@github.com: Path/repository. Git clone a distant branch library

git clone git@server:path/repo.git local set up remote repository corresponding branch

git checkout-b Branch Origin/branch latest submission from remote

Git Pull Association and push local repository to remote library

Git push-u origin master local branch push to remote library

git push view remote warehouse status

git remote show origin
git remote-v local branch vs. remote Branch

git diff <branch> origin/<branch> forcing remote libraries to overwrite local

git fetch--all
git reset--hard origin/master
Git pull updates remote information

GIT Remote update tracks the branch remotely

Git fetch origin branch-name establish local and remote branch connections

Git branch--set-upstream-to <branch> origin/<branch> clone specified branch

git clone-b <branch> git@server-name:path/<repo-name>.git Merge conflicts

Manually resolve conflicts after conflicts file –>git->resolve Conflicts The actual combat problem and the solution method summary

No commit after commit problem encountered: Vim:caught deadly signal SEGV, unable to continue operation git
? You can only restart the Git window.
Exit Log interface: Q key to exit

Delete section log?
Git reset–hard commit-id:head point to the Commit-id version, log shows only the current head version, and all of the logs can still be displayed after fallback

Delete all log? Pending study

View Help: Git–help; Specify commands to help Git log-help;

Git reset–hard head-id: Fallback to the specified HEAD version, ID can be viewed with git reflog version fallback:

git reset head^

When no –hard:
Unstaged changes after Reset:m <file>;

When you have –hard:
Full command: git reset--hard head^
HEAD is now at <commit-id>

Result head is pointing to the specified version

Not a commit:
checkout– prompt file matching, need Reset or rest HEAD to clear the buffer before revocation,-f Force delete cannot be undone

Already commit:
After reset checkout can not be revoked, want to undo can only Reset–hard Commit-id or Reset–hard head fallback to submit delete, cannot rollback the specified file

Prompt when adding remote repositories: fatal:remote origin already exists. Enter VI:

Vi
. git/config Delete Remote "origin" Exit VI Editor:

ESC after Shift+zz save exit Remote Library and local library operations related issues and summary

in-Repository files, multiple branch shares under the same path, branch submissions, merging into mainline

the remote library default name is based on what we created when we first connected to the remote library

Git Pull hints

There is no tracking information for the current branch description The connection relationship between the local branch and the remote branch is not created

Git Pull hints
Error:the following untracked working tree files would be overwritten by merge: .....

Please move or remove them before you can merge.

Aborting

git clean-d-fx ""
which
x-– Delete files that have ignored files that have not been recognized by git
d-– Delete files that have not been added to the GIT path
f-– forcing local and remote operational processes to run

After entering the specified directory
Initialize Warehouse if no warehouse
Associated remote repositories: Git remote add Origin git@server-name:path/<repo-name>.git
To view remote Warehouse information:
Git remote-v Two scenarios: When you have not clone a remote branch:

git remote show origin

git Remote update

Git pull

Above three command prompt:

Gitlab:the project were looking for could is found.

Fatal:could not read from remote repository.

Please make sure the correct access rights and the repository exists. checkout-b <branch> <origin>/<branch>:

Tips:
Fatal: ' Origin/branch ' is not a commit and a branch ' branch ' cannot was created from it checkout <branch> <ori When Gin>/<branch>

Tips:
Error:pathspec ' branch ' did not match any file (s) known to Git.

Error:pathspec ' Origin/branch ' did not match any file (s) known to Git.

Can only be cloned at this time
git clone git@server-name:path/<repo-name>.git Get warehouse re-operation

when you are studying to verify that the remote branch has been cloned:

local warehouse and Remote warehouse connection established, default to Master branch, need to switch to clone Warehouse code path, continue operation

Git remote show origin hint tracked
git Remote update
Git pull no latest submission hint already up-to-date
git fetch
The above command can be followed by normal operation

Establish and switch to the local branch corresponding to the remote library
git checkout-b branch Origin/branch,
Change the master branch code that has been clone to the specified branch code

git checkout master switch to Master Branch, code re-download

The branch switching process workspace code follows the branch changes

Git Status View warehouse status, without modifying the workspace state of the warehouse is unchanged working tree clean

Tracking Remote Libraries
Git fetch Origin Branch
Fetch latest commit GIT pull Origin branch specify branch or git fetch default current corresponding branch
Establish a connection to git branch--set-upstream-to <branch> origin/<branch>

Problem: Encountered git pull and git remote update does not fetch prompt new and not tracked, to be reproduced note: actual development needs

The repository code will be different if you need to commit the workspace to the local branch warehouse before you switch the branch, and then switch branches after committing.

Git stash temporarily save the workspace, remember the stash ID, then switch the branch operation, cut back to the branch after the Git

Stash pop or stash apply <stashid> restore original Workspace Remember:

Locally modified branch: for local modification

Remote Sync Branch: For pull and push, local modify branch merge to this branch, then push

Switch branches before committing or temporarily saving locally modifying branch modifications to the local repository so that the branch can be cut back to continue modifying the daily Git code action process after the local warehouse has been associated with the remote warehouse:

View remote repository Information git remote show origin
Track latest commit GIT fetch Origin branch
When pulling the latest commit git pull local warehouse is not associated with a remote:

Associate a local warehouse to a remote repository,
Clone Remote Branch,
GIT fetch tracking,
Git pull Fetch
git push

Tips:
Fatal:the Upstream branch of your current branch does not match
The name of your current branch. To push to the upstream branch
On the remote, use
Git push Origin head:<branch>
To push to the branch of the same name on the remote, use
Git push origin <branch> full submission process

Git stash save local workspace

git checkout < remote branch> switch to remote branch

GIT pull fetch remote commit

Git checkout < local branch> back to local

git merge--no-ff-m "" < remote branch> Remote branch Merge to local, resolve conflict

git Checkout < remote branch>

git merge--no-ff-m "" < local branch> local branch merge to remote

Git push origin head:<branch> or git push

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.