git checkout -b tmp # "tmp" or pick a better name for your local changes branchgit add -Agit commit -m 'tmp'git pullgit checkout master # Or whatever branch you were on originallygit pullgit diff tmp
git reset HEAD --hard # To remove all not committed changes!git clean -fd # To remove all untracked (non-git) files and folders!
警告:上述命令仅在您没有提交它们时才会导致数据/文件丢失!如果您不确定,请先备份整个存储库文件夹。
然后再拉一次。
如果上面没有帮助并且您不关心未跟踪的文件/目录(以防万一,请先备份),请尝试以下简单步骤:
cd your_git_repo # where 'your_git_repo' is your git repository folderrm -rfv * # WARNING: only run inside your git repository!git pull # pull the sources again
# Fetch the newest codegit fetch
# Delete all files which are being added, so there# are no conflicts with untracked filesfor file in `git diff HEAD..origin/master --name-status | awk '/^A/ {print $2}'`dorm -f -- "$file"done
# Checkout all files which were locally modifiedfor file in `git diff --name-status | awk '/^[CDMRTUX]/ {print $2}'`dogit checkout -- "$file"done
# Finally pull all the changes# (you could merge as well e.g. 'merge origin/master')git pull
#/bin/sh
# Fetch the newest codegit fetch
# Delete all files which are being added,# so there are no conflicts with untracked filesfor file in `git diff HEAD..origin/master --name-status | awk '/^A/ {print $2}'`doecho "Deleting untracked file $file..."rm -vf "$file"done
# Checkout all files which have been locally modifiedfor file in `git diff HEAD..origin/master --name-status | awk '/^M/ {print $2}'`doecho "Checking out modified file $file..."git checkout $filedone
# Finally merge all the changes (you could use merge here as well)git pull
git fetch origin branchnamegit checkout -f origin/branchname // This will overwrite ONLY new included filesgit checkout branchnamegit merge origin/branchname
git checkout branchname # go to your branchgit fetch origin branchname # fetch the remotegit checkout -b backup # optionally, mark your remote as a backupgit branch -f branchname origin/branchname # force your local branch to be equal to the fetched origin/branchname