文章目录常见问题与解决方案问题1git clone 后本地无工程代码问题2git pull 或 git merge 时提示文件将被覆盖方法一放弃本地修改不可恢复方法二使用 git stash 暂存更改问题3git pull 时未指定分支报错问题4Windows 下 Git 中文乱码常见问题与解决方案问题1git clone后本地无工程代码问题描述执行git clone [URL]后在本地工作区未看到或找不到项目代码。原因git clone仅将远程仓库拉取至本地但未自动创建和切换至对应的工作分支因此工作区中不显示文件。解决方案拉取远程分支并同时创建本地分支# 1. 查看远程仓库信息gitremote# 2. 拉取指定远程分支并创建对应的本地分支gitcheckout-b[本地分支名][远程仓库名]/[远程分支名]问题2git pull或git merge时提示文件将被覆盖报错信息示例error: Yourlocalchanges to the following files would be overwritten by merge: .gitignore GameServerDev/script/script_server/dbfiles/DECISION_TAB.LOG Please commit your changes or stash them before you merge. Aborting解决方案方法一放弃本地修改不可恢复此操作会彻底丢弃所有未提交的更改请谨慎使用。gitreset--hard说明git reset --hard将工作区与暂存区完全回退到上一次提交状态并清除所有未提交的变更。方法二使用git stash暂存更改保存当前工作进度gitstash# 或添加说明信息gitstash save暂存说明执行拉取或合并操作。恢复暂存的内容gitstash pop# 恢复并删除栈顶记录# 或gitstash apply# 恢复但保留栈顶记录相关管理命令gitstash list# 查看所有暂存记录gitstashclear# 清空所有暂存记录问题3git pull时未指定分支报错报错信息示例You asked to pull from the remoteorigin, but did not specify a branch. Because this is not the default configured remoteforyour current branch, you must specify a branch on thecommandline.原因当前本地分支未与远程分支建立跟踪关系。解决方案将本地分支与远程分支关联gitbranch --set-upstream-to[远程仓库名]/[远程分支名][本地分支名]问题4Windows 下 Git 中文乱码解决方案在 Git Bash 中执行以下命令进行全局配置gitconfig--globalcore.quotepathfalsegitconfig--globalgui.encoding utf-8gitconfig--globali18n.commit.encoding utf-8gitconfig--globali18n.logoutputencoding utf-8说明以上设置可解决大部分 Windows 环境下中文文件名和日志内容显示乱码的问题。
Git使用:Git使用问题及解决方法总结
文章目录常见问题与解决方案问题1git clone 后本地无工程代码问题2git pull 或 git merge 时提示文件将被覆盖方法一放弃本地修改不可恢复方法二使用 git stash 暂存更改问题3git pull 时未指定分支报错问题4Windows 下 Git 中文乱码常见问题与解决方案问题1git clone后本地无工程代码问题描述执行git clone [URL]后在本地工作区未看到或找不到项目代码。原因git clone仅将远程仓库拉取至本地但未自动创建和切换至对应的工作分支因此工作区中不显示文件。解决方案拉取远程分支并同时创建本地分支# 1. 查看远程仓库信息gitremote# 2. 拉取指定远程分支并创建对应的本地分支gitcheckout-b[本地分支名][远程仓库名]/[远程分支名]问题2git pull或git merge时提示文件将被覆盖报错信息示例error: Yourlocalchanges to the following files would be overwritten by merge: .gitignore GameServerDev/script/script_server/dbfiles/DECISION_TAB.LOG Please commit your changes or stash them before you merge. Aborting解决方案方法一放弃本地修改不可恢复此操作会彻底丢弃所有未提交的更改请谨慎使用。gitreset--hard说明git reset --hard将工作区与暂存区完全回退到上一次提交状态并清除所有未提交的变更。方法二使用git stash暂存更改保存当前工作进度gitstash# 或添加说明信息gitstash save暂存说明执行拉取或合并操作。恢复暂存的内容gitstash pop# 恢复并删除栈顶记录# 或gitstash apply# 恢复但保留栈顶记录相关管理命令gitstash list# 查看所有暂存记录gitstashclear# 清空所有暂存记录问题3git pull时未指定分支报错报错信息示例You asked to pull from the remoteorigin, but did not specify a branch. Because this is not the default configured remoteforyour current branch, you must specify a branch on thecommandline.原因当前本地分支未与远程分支建立跟踪关系。解决方案将本地分支与远程分支关联gitbranch --set-upstream-to[远程仓库名]/[远程分支名][本地分支名]问题4Windows 下 Git 中文乱码解决方案在 Git Bash 中执行以下命令进行全局配置gitconfig--globalcore.quotepathfalsegitconfig--globalgui.encoding utf-8gitconfig--globali18n.commit.encoding utf-8gitconfig--globali18n.logoutputencoding utf-8说明以上设置可解决大部分 Windows 环境下中文文件名和日志内容显示乱码的问题。