Git command line operation and error message solution (continuously updated...)

1: Command line operation

1.1: View the current branch : git branch -a or -v

1.2 : If there is a new branch and it is not displayed using the above command, just use: git fetch

1.3: Switch branches : git checkout  branchname

1.4: Solve the problem that git pull needs to enter the username and password every time: git config --global credential.helper store (you need to enter it once after setting, and it will take effect next time)

1.5: Create a branch  git branch branchname

1.6: Delete branch git branch -d branchname or  git branch -D branchname (forced deletion) 

1.7: Merge branches : If you want to merge the developing branch (develop) into the stable branch (master), first switch the master branch: git checkout master. Then perform the merge operation: git merge develop . If there is a conflict, you will be prompted to call git status to view the conflicting files. Resolve the conflict, then call git add or git rm to stage the resolved file. After all conflicts are resolved, git commit commits the changes.

1.8: Temporarily store the current branch: For example, git stash   wants to pull the latest code, but does not want to add a new commit, or in another case, in order to fix an urgent bug, stash first, so that you can return to your last commit, and then fix the bug. stash pop, to continue the original work.
Basic command:
$git stash
$do some work
$git stash pop

Advanced:

git stashsave "work in progress for foo feature" 

When you use the 'git stash' command many times , your stack will be full of uncommitted code, at this time you will be a little confused about which version to apply back,

The ' git stash list ' command can print out the current Git stack information. You only need to find the corresponding version number. For example, use ' git stash apply stash@{1} ' to specify the version number as stash@{1 } The work is taken out , and when you have all the stacks applied back, you can use ' git stash clear ' to clear the stack.


git stash          # save uncommitted changes
# pull, edit, etc.
git stash list     # list stashed changes in this git
git show stash@{0} # see the last stash
git stash pop      # apply last stash and remove it from the list

git stash --help   # for more info

2: Error message:

2.1:error: Your local changes to the following files would be overwritten by merge:

                            protected/config/main.php

                            Please, commit your changes or stash them before you can merge.

Solution: If some configuration files in the system are modified on the server, and then some new configuration items are added in subsequent development,

When publishing this configuration file, code collision will occur. If you want to keep the changes made on the production server, just merge the new configuration items,

git stash

git pull

git stash pop

You can then use git diff -w +filename to confirm that the code was automatically merged.

If you want to completely overwrite the local working version with the files in the codebase. Here's how:

git reset --hard

git pull

2.2 git switch branch error: error: pathspec 'origin/XXX' did not match any file(s) known to git.

There is a branch test on the project, the remote branch cannot be seen using git branch -a, and the command git checkout test is used directly to report an error

Solution: 

1. Execute the command git fetch to retrieve the updates of all branches

2. Execute git branch -a to see the test branch (the branch information has been updated)

3. Switch branch git checkout test


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324645199&siteId=291194637