尝试签出分支时git错误

时间:2018-01-28 03:03:50

标签: git github version-control

我在尝试执行git checkout时收到此错误:

git checkout BranchName
  

错误:以下文件的本地更改将被结帐:

覆盖
git status
On branch BranchName
Your branch is ahead of 'origin/BranchName' by 5 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

我不想提交这些更改。

如何在结帐时忽略这些文件类型:

  • *。登录
  • *。IML
  • .idea
  • .slcache

3 个答案:

答案 0 :(得分:1)

如果您根本不想保留更改,则只需撤消更改即可。

# Warning: you will lose any uncommitted changes
git checkout -- <files>

如果您希望稍后保留更改,但又不想提交更改,则可以存储它们,这样可以将它们保存在存储中并在您进行更改之前将工作树返回

git stash

查看/恢复您的存储空间

# Shows list of your stashes
git stash list

# Shows the specific changes in the most recent stash
git stash show

# Applies the most recent stash to your working tree
git stash apply

# Applies the most recent stash to your working tree and removes the stash from your stashes
git stash pop

答案 1 :(得分:1)

首先,如果你想checkout到另一个分支,你需要对你的更改做一些工作。那些是

  • 如果您需要进一步更改,可以stashFor more
  • 如果您不需要更改,则可以使用resetFor more
  • 如果您需要进一步更改,也可以利用cherrypick的优势。 For more
  

结帐:目标输出* .log * .iml .idea .slcache

您可以创建.gitignore文件,而不是根据需要配置此文件。

EX:忽略*.log个文件 在.gitignore文件中设为*.logdirectory设置为**/directory_nameFor more help

答案 2 :(得分:0)

如果您不希望git停止切换到其他分支(因为工作树未提交更改),只需通过添加-f选项强制切换到另一个分支在git checkout branchname命令中:

git checkout branchname -f

如果您不想再在git repo中跟踪cretain文件夹和文件类型,可以在.gitignore中添加带通配符的文件夹和文件,并删除git repo中的缓存:

# Add .gitignore file
touch .gitignore

然后在.gitignore内容中添加以下行:

target
out
*.log
*.iml
.idea
.slcache

执行命令:

git rm target --cached
git rm out --cached
git rm *.log --cached -r
git rm *.iml --cached -r
git rm .idea --cached
git rm .slcache --cached
git add .
git commit -m 'ignore certain files from git repo'
相关问题