git resolves local conflicts +git common commands

Source: Internet
Author: User
Tags commit diff file diff git clone git commands

git resolves local conflicts

The process is very simple, mainly using the git stash command for processing, divided into the following steps to deal with.

1. Store local Modifications first

$ git stash
This allows all local modifications to be temporarily stored. is to use Git stash list to see the saved information:

Git stash Staging changes
Git stash Staging changes

Where stash@{0} is the tag you just saved.

2. Pull Content

After the local modifications are staged, the pull is ready.

$ git pull
3. Restore staged content

$ git stash pop stash@{0}
The system prompts similar information as follows:

Auto-merging C/ENVIRON.C
CONFLICT (content): Merge CONFLICT in C/ENVIRON.C
This means that the system automatically merges the modified content, but there are conflicts that need to be resolved.

4. Resolve conflicting parts of the document

Open the conflicting file and you will see something similar to the following:

Git conflict content
Git conflict content

The content between updated upstream and ===== is the content of pull down, and the content between = = and stashed changes is locally modified content. In this case, Git does not know what line of content is needed, so you have to decide what you want.
Once the resolution is complete, it can be submitted normally.

Common git commands

View File diff
git diff # Compare current file and staging area file diff git diff
git diff # Compare the differences between two commits
Git diff.. # Compare between two branches
Git diff–staged # Compare staging area and repository differences
Git diff–cached # Compare staging area and repository differences
git diff–stat # Just compare statistics
View Commit Record
git log git log # View the file for each commit record
git log-p # view diff for each detail change
Git log-p-2 # See a diff of the last two detailed edits
Git log–stat #查看提交统计信息
Tig
You can use TIG instead of diff and Log,brew install TIG on your Mac
Git Local Branch Management
View, toggle, create, and delete branches
Git br-r # View Remote Branch
Git BR # Create a new branch
Git br-v # View the last commit information for each branch
Git br–merged # View branches that have been merged into the current branch
Git br–no-merged # View branches that have not been merged into the current branch
Git Co # switch to a branch
Git Co-b # Create a new branch and switch to the past
Git Co-b # Create a new new_branch based on branch
Git Co ID # Checkout A history commit record, but without branching information, switching to another branch will automatically delete
Git coid # Checkout A history commit record, but without branching information, switching to another branch will automatically delete git Co id-b # Checkout A history commit record and create a branch
git br-d # Delete a branch
git br-d # Force a branch to be removed (a branch that is not merged will need to be forced when it is deleted)
Branch Merging and Rebase
Git merge # Merges branch branches into the current branch
git merge Origin/master–no-ff # do not fast-foward merge so you can generate a merge commit
git rebase Master # rebase Master to branch, equivalent to: Git co && git rebase master && git co master && git Merge
git patch management (for easy development of synchronization on multiple machines)
git diff >: /sync.patch # Generate Patches
git apply. /sync.patch # Patching
Git apply–check. /sync.patch #测试补丁能否成功
Git staging management
Git Stash # Staging
git Stash List # column all stash
git stash apply # recover staged content
git stash Drop # Delete Staging area
GIT Remote branch Management
Git pull # Crawl all branches of remote repository update and merge to local
Git pull–no-ff # Crawl All branch updates from the remote repository and merge them locally, not fast-forward merge
Git fetch origin # crawl Remote repository update
git merge Origin/master # merges the remote main branch into the local current branch
Git co–track origin/branch # Track a remote branch to create the appropriate local branch
Git co-b origin/# Create local branch based on remote branch, same as above
Git push # push all branches
Git push Origin Master # pushes the local landlord branch to the remote main branch
Git push-u Origin Master # pushes the local landlord branch to the remote (if no remote main branch is created to initialize the remote repository)
Git push Origin # Creates a remote branch, origin is the remote repository name
Git push Origin: # Create a remote branch
Git push origin: #先删除本地分支 (git br-d), and then push to delete the remote branch
GIT Remote repository Management
GitHub
Git remote-v # View remote server address and warehouse name
git remote Show Origin # View the Server warehouse status
Git remote add Origin git@ Github:robbin/robbin_site.git # Add repository Address
git remote Set-url Origin git@ Github.com:robbin/robbin_site.git # set remote Warehouse address (used to modify remote warehouse address)
Create a remote Warehouse
git clone–bare robbin_site robbin_site.git # Create a version-only warehouse with a versioned project
Scp-r my_project.git git@ git.csdn.net:~ # Upload the repository to the server
mkdir robbin_site.git && cd robbin_site.git && git–bare init # Creating a pure warehouse on the server
Git remote add Origin git@ Github.com:robbin/robbin_site.git # Set up the repository address
Git push-u Origin Master # client First Commit
Git push-u origin Develop # First submits the local develop branch to the remote develop branch, and the track
git remote Set-head Origin Master # Set the remote repository head to the master branch
You can also command settings to track remote libraries and local libraries
git branch–set-upstream master Origin/master
git branch–set-upstream Develop Origin/develop

View, add, submit, delete, retrieve, reset modified files
git help # shows command's help
Git show # shows the content of a commit git show $id
git co–# Discard workspace modifications
Git Co. # Discard Workspace Modifications
Git add # commits the work file modification to the local staging area
git Add. # submit all the modified work files to staging area
git rm # Delete files from the repository
git rm–cached # removes files from the repository, but does not delete files
Git reset # Recover from staging area to working file
Git reset–. # Recover from Staging area to working file
Git Reset–hard # Restores the last state that was submitted, discarding all of the changes since the last commit
Git ci git ci. Git ci-a # git add, git rm and git ci are all combined to make git ci-am "some comments"
Git ci–amend # Modify the last commit record
Git revert # Restores the state of a commit, and the recovery action itself also creates a commit object
git revert HEAD # Restores the state of the last commit

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.