[git] Problems that may arise in practical applications

1. The solution to conflicts in git pull times | How to deal with code conflicts

question:

error: Your local changes to the following files would be overwritten by merge:
       xxx/xxx/xxx.java
Please, commit your changes or stash them before you can merge.
Aborting

Method 1: git stash command temporary storage.

  1. The git stash command first temporarily stores all local modifications, where stash@{0} is the mark just saved. Subsequent access can be made through this tag.
  2. git pull command, pull code
  3. git stash pop stash@{0}, restore the stash content. Read the last saved content from the Git stack and restore the relevant content in the workspace. Since there may be multiple Stash contents, a stack is used to manage them.
    If the system prompts information similar to the following:
    Auto-merging c/environ.c CONFLICT (content): Merge conflict in c/environ.c
    means that the system automatically merges the modified content, but there are conflicts, which need to be resolved.
  4. Resolve the conflicting part of the file.
    The content between Updated upstream and ===== is the content of the pull, and the content between ==== and stashed changes is the content of local modification. In this case, git does not know which line of content is needed, so it has to determine the required content by itself.
    After the solution is completed, you can submit it normally.
    5. To delete stash,
    use the git stash drop stash@{0} command. If you do not add a stash number, the default is to delete the latest one, that is, the number 0. Or git stash clear command to clear all stash

git command:
git stash pop will read and restore from the most recent stash.
git stash list: Display all backups in the Git stack, you can use this list to decide where to restore from.
git stash clear: Clear the Git stack. At this time, using graphical tools such as gitg will find that all the nodes of the original stash have disappeared.
git stash: Back up the content of the current workspace, read the relevant content from the latest submission, and ensure that the workspace is consistent with the content of the last submission. At the same time, save the current workspace content to the Git stack

Method 2: Abandon local modification and directly overwrite

git reset --hard
git pull

Method 3: commit

After commit, pull shows conflicts -> manually merge to resolve conflicts -> recommit -> push
1. First submit the local changes to the local warehouse;
2. Pull the code from the remote warehouse and use git pullthe command;
3. If there is a conflict, manually
4. After the resolution is completed, use git addthe command to add the file to the temporary storage area;
5. Use git commit -m "message"the command to submit the modification;
6. Finally, use the command git push origin masterto push the local code to the remote warehouse.
or
1. First use the git status command to view the conflicting files, and confirm the conflicting files and conflicting locations.
2. Open the conflicting file, find the conflicting code block according to the prompt, manually modify the code, and resolve the conflict.
3. After the modification is completed, use the git add command to add the modified file to the temporary storage area.
4. Use the git commit command to submit the modification and add some description information.
5. Finally, use the git push command to push the local code to the remote warehouse.

Guess you like

Origin blog.csdn.net/m0_46459413/article/details/131422675