Git command usage and common problem solving

Git command usage:  
Take the CTS project as an example: Beijing Haidian credit card payment [Tel/WeChat: 135-2093-5605], visa card cash out, point POS machine ◆Long-term effective ◆Welcome to inquire and handle!  
1. First install the Git client , and then configure to generate sshKey.  
First download the code from the server to the local, the following command:  
git clone [email protected]:tx/cts.git  
is the code under the downloaded master branch by default. If you need to switch to a branch, you need to enter the cts directory , and then git checkout feature_20160701_yanshi, indicating that you have entered the branch of feature_20160701_yanshi, and then git pull, you can get all the latest files under this branch.  
Then you can do development locally, if you need to submit:  
git add . By default, all files in the current directory (including new (added to git management), changed, deleted (already managed by git)), if not added file can omit this step.  
git commit -a -m "comment" to submit to the local warehouse (the comment is what you changed this time)  
git push to submit to the remote warehouse  

Common problem solving:  
1.1 git stash command Use  
git stash save –a '111111' to save the current work  If a branch is under development halfway, and you need to switch to another branch, but you don't want to submit the locally modified code, you can use the git stash command to save it .
(git stash save -a 11111111 to save with 11111111 as the prompt name) 
What if you want to restore a worksite on a branch: first check the stash queue with git stash list. Determine which job site to restore to the current branch. Then use git stash pop stash@{num}. num is the number of the job site you want to restore.  
1.2 Switching branch error solution  

At this time, you need to enter the directory under git version control to switch branches correctly. The correct approach is as follows:  

1.3 Git push error resolution  
When Updates were rejected because of the tip occurs, due to the development under a local branch, the development is completed, to submit, git push reports an error, Updates were rejected because the tip, which means remote resources There are the latest files in the library, your local files are not up-to-date and need to be updated (pull). As follows:  
At this time, you need to back up your modified files, then download the latest version of the current branch, do secondary development on this basis, then git commit –m '' , and finally git push.  

The solution is:  
1. First back up the modified files one by one, then go to another new directory, execute the  
git clone [email protected]:tx/cts.git  
command, and then switch to the branch you want to develop Below (feature_20160706_userManage), execute the git pull command to ensure that the latest version under the current branch is obtained,  
2. Then import it into eclipse, and do the secondary development of the modified files (the first step has its own backup files).  
3. Then enter the git command line and switch to the current branch (git checkout feature_20160706_userManage 
), execute the git commit –m 'comment' command, and then execute git push to submit all remote branches.  
Verification method:  
Create a new directory, execute the git clone [email protected]:tx/cts.git command, then switch to the feature_20160706_userManage branch, and execute the git pull command to see if the code you modified is the latest version.  

1.4 Detailed explanation of  
git status command The git status command can list all files in the current directory that have not been managed by git and files managed by git and modified but not yet committed (git commit).  
For example;  
git status  
# On branch master  
# Changes to be committed:  
# (use "git reset HEAD <file>..." to unstage)  
#  
# modified: 2.txt  
#  
# Changes not staged for commit:  
# (use " git add <file>..." to update what will be committed)  
# (use "git checkout -- <file>..." to discard changes in working directory)  
#  
# modified: 1.txt  
# 
# Untracked files:  
# (use "git add <file>..." to include in what will be committed)  
#  
# 1. The content listed in "Changes to be committed" in the 1.log  
command is the content in the Index, Enter Git Directory after commit.  
The content listed in "Changed but not updated" in the command is the content in the Working Directory, and will enter the Index after add.  
The content listed in "Untracked files" in the command is the content that has not been tracked by Git. After add, enter the Index and  
pass git status -uno to only list all files that have been managed by git and have been modified but not submitted. 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693654&siteId=291194637