Git Conflict error: Your local changes would be overwritten by merge. Commit, stash or revert them to proceed?

Git Conflict error: Your local changes would be overwritten by merge. Commit, stash or revert them to proceed?

 

How to Solve this error:

 

There are three solutions:

The first type: (Strongly not recommended, to be scolded) Ignore, directly commit your own code.

git commit -m “your msg”

The second: stash (strongly recommended method)

stash translates as “hidden”, as follows:

git stash
git pull
git stash pop
Then diff the file to see the automatic merge and make the necessary changes.

git stash: Back up the content of the current workspace, read the relevant content from the most recent 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.
git stash pop: Read the last saved content from the Git stack and restore the relevant content of the workspace. Since there may be multiple Stash contents, they are managed by stacks. Pop will read the contents from the most recent stash and restore it.
git stash list: Display all the backups in the Git stack. You can use this list to determine where to restore.

git stash clear: Clear the Git stack. At this point, using graphical tools such as gitg, you will find that which nodes of the original stash have disappeared.

The third type (strongly not recommended, because you will overwrite what you have written, not recommended) hard coverage: abandon local modifications and directly overwrite the local code with the code on git:

git reset –hard
git pull

Supplement the above operations in idea:

Step 1: Right-click the project name->git->repository-> stash changes and fill in the information to backup

Step 2: Right-click the project name->git->repository->pull

Step 3: Right-click the project name->git->repository->unstash changes

In the third step, your local changes would be overwritten by merge, etc. may appear, because you have modified the files you pulled down before saving locally.

When this happens, click on the view below Your local changes would be overwritten by merge, select one file for one file, and there are three files when you select.

Left, middle and right, the middle is the result file, the left is the large file that was pulled down, and the right is the file that you modified locally. If you want to use the file that was pulled down, select accept left. If you want to save the local modification, select accept right. can

Method 2 stash:

Method 3 Hard Cover:

Commonly used git stash commands:

(1) git stash  save “save message”: When performing storage, add remarks to facilitate searching. Only git stash is also possible, but it is not easy to identify when searching.

(2) git stash list   : check which stores are stored in stash

(3) git stash show  : show what changes have been made, the default show is the first store, if you want to show other stores, add stash@{ $num}, such as the second git stash show stash@{1}

(4) git stash show -p  : Display the changes of the first store. If you want to display other stores, command: git stash show stash@{ $num} -p, such as the second one: git stash show stash@{1 } -p

(5) git stash apply  : apply a certain storage, but will not delete the storage from the storage list. The first storage is used by default, that is, stash@{0}. If you want to use another one, git stash apply stash@{ $ num}, such as the second one: git stash apply stash@{1}

(6) git stash pop  : command to restore the previously cached working directory, delete the corresponding stash in the cache stack, and apply the corresponding modification to the current working directory. The default is the first stash, that is, stash@{0}, If you want to apply and delete other stash, command: git stash pop stash@{ $num}, such as apply and delete the second one: git stash pop stash@{1}

(7) git stash drop  stash@{ $num}: discard stash@{$ num} storage, delete this storage from the list

(8) git stash clear :Delete all cached stash

Similar Posts: