How does git pull believe that the remote end is completely correct and ignore its own modifications

git pullis a command to merge changes from the remote repository into the local branch. If you are sure that the changes on the remote branch are correct and want to ignore the local changes, you can use the following steps to overwrite the local changes:

  1. First, make sure you have Git configured as the current project. Enter the following command at the command line:
 
 
git config user.name "Your Name" git config user.email "[email protected]"

  1. Then, reset the current branch to the state of the remote branch with the following command. This will undo all changes you made locally:
 
 
git fetch origin 
git reset --hard origin/<branch_name>

where <branch_name>is the name of the remote branch you want to reset, such as "main" or "master".

  1. If you still have untracked files, delete them with:
 
 
git clean -fd

Your local branch should now be fully in sync with the remote branch, ignoring your previous local modifications.

Note that executing these commands will result in loss of local changes, so make sure you have a backup of your work before executing them.

Guess you like

Origin blog.csdn.net/mp624183768/article/details/130120539