FAQ about git commands

1. git pull command

1.1 Question 1: Enter the git pull command prompt as follows:

error: your local changes would be overwritten by cherry-pick.
hint: commit your changes or stash them to proceed.
fatal: cherry-pick failed

Reason: The local code has been modified, but the modification has not been submitted or saved.
Solution:
1. If you want to pull the latest code from the git server, but do not want to discard the local modification.
First use git stash to temporarily seal the modified code, wait for the latest code from the git server to be pulled, and then use git stash pop to restore the local modification

git stash
git pull origin master
git stash pop

2. If you want to completely cover the local code and only keep the server-side code, then go back to the previous version directly, and then proceed

git reset --hard HEAD^
git pull origin master

1.2 Question 2: Enter the command prompt of git pull or git stash pop as follows:

Unmerged paths:
  (use "git restore --staged <file>..." to unstage)
  (use "git add <file>..." to mark resolution)
        both modified:   app/src/main/java/com/exa/tester/TesterActivity.kt

<<<<<<< Updated upstream, ======= and >>>>>>> Stashed changes appear in the TesterActivity.kt file. This problem occurs because the code pulled from the server conflicts with the local Yes, but it has been switched to the latest branch of the server, and the conflict can be resolved locally
<<<<<<< The code between Updated upstream and ======= is the server code you pulled, then == ===== to >>>>>>> Stashed changes are your own locally modified code. In this way, it is very convenient to modify with a clear conflict marker

  • To keep the local code, delete <<<<<<< Updated upstream to =======
  • To keep the server code, delete ======= to >>>>>>> Stashed changes

1.3 Question 3: Enter the git pull --rebase command prompt as follows:

You are not currently on a branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.

    git pull <remote> <branch>

Solution 1: Switch to the specified remote branch first, and then update the code

 git checkout 分支名    // 切换到指定远程分支
 git pull --rebase

Solution 2: Directly update the code of the remote specified branch to the local branch

git pull origin 分支名

Two, git push command

2.1 Question 1

remote: ERROR: commit 99cd9fd: missing Change-Id in message footer
remote:
remote: Hint: to automatically insert a Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/
remote: and then amend the commit:
remote:   git commit --amend --no-edit
remote:
To ssh://127.0.0.1:8080/packages/apps/Xty
 ! [remote rejected] HEAD -> refs/for/master (commit 99cd9fd: missing Change-Id in message footer)
error: failed to push some refs to 'ssh://127.0.0.1:8080/packages/apps/Xty'

The problem is that the commit-msg file is missing, so the Change-Id cannot be found when submitting,
just complete the Change-Id according to the prompt, and send the commands in sequence

gitdir=$(git rev-parse --git-dir); scp -p -P 29418 [email protected]:hooks/commit-msg ${gitdir}/hooks/
git commit --amend --no-edit
git push origin HEAD:refs/for/master

3. The submitted code prompts Merge Conflict

In the same warehouse, if a piece of code submitted by A is not merged, and the code submitted by B conflicts with the code submitted by A but is merged before A, the status of this submission of A will display the Merge Conflict solution
:
1. Use the git pull --rebase command to update the latest code of the warehouse locally
2. Cherry Pick the code submitted by A to the local, and the local will prompt ""
3. Enter git status to see which files are in conflict,
4. Return Return these files, enter in sequence

git reset HEAD 文件名
git checkout -- 文件名

5. Add the modification to which files just now
6. Enter the following command, which will overwrite the submission of A

git add .
git commit    // 注意,这里是git commit,不要加--amend
git push origin 分支名

Guess you like

Origin blog.csdn.net/qq_34205684/article/details/128038918