Git error: The following untracked working tree files would be overwritten by checkout

When switching branches in idea, such an error occurs, resulting in the failure of normal switching

:error: The following untracked working tree files would be overwritten by checkout

According to the error prompt, it is due to some problems caused by untracked working tree files. So as long as we solve these untracked files, we can solve this problem. If you want to keep the changes made on the production server and only incorporate the new configuration items, the processing method is as follows:
git stash
git pull
git stash pop
then you can use git diff – W + file name to confirm the automatic code merging.
conversely, If you want to completely cover the local working version with the files in the code base, the method is as follows:
git reset — hard
git pull
where git reset is for the version, if you want to back the local modification for the file, Use
untracked working tree file
reference: http://blog.csdn.net/sheismylife/article/details/7204345
Note when writing scripts for automatic compilation and deployment:
if you want to write scripts on C2 to automatically obtain the latest code from S1, you should pay attention to:
1, Otherwise, the password will be required every time git pull
2. Do not submit the intermediate files in the project to S1, such as the files in the build directory of cmake project and the files in the target directory of Maven project. Otherwise, the next time you use git pull on C2 and other clients, you will report an error similar to this:
error: untracked working tree file ‘public/images/icon. GIF’ would be written by merge.
you need to execute the following command to repair:
Git reset — hard head
git clean – F – d
git pull

Similar Posts: