在Git中的分支之间未记录的文件 [英] Untracked files between branches in Git

查看:84
本文介绍了在Git中的分支之间未记录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这里寻找答案,看来我可能只是对git分支应该如何工作做出错误的假设。

I've been searching around here for to look for an answer and it seems I may just be making incorrect assumptions on how git branches are supposed to work.

我有我的 master 分支,并且创建了一个名为 profiles 的功能分支,我正在做一些特定的工作配置文件。在处理配置文件时,我更改了5或6个文件,并添加了另外5或6个新文件。我需要切换回 master 分支来修复一个快速错误,并注意到那里的所有新文件和修改过的文件。我猜这是有道理的,因为git不会从 master 分支中删除未跟踪的文件,并将它们带回我的配置文件因为它们实际上没有跟踪。但是对现有文件的更改如何呢?他们为什么出现在主分支中。

I have my master branch and I've created a feature branch called profiles where I'm doing some specific work to profiles. While working on profiles I've changed 5 or 6 files and added another 5 or 6 new files. I needed to switch back to the master branch to fix a quick bug and noticed all the new files and modified files where in there as well. I guess this makes sense since git isnt going to remove untracked files from the master branch and bring them back for my profiles branch since they are, in fact, untracked. But what about the changes to existing files. Why are they showing up in the master branch.

这里最好的做法是什么。我还没有准备好在本地提交更改。如果我只是隐藏所有这些更改,切换到 master ,进行小修改,切换回配置文件,然后重新应用隐藏?

Whats the best practice here. I'm not ready to commit the changes locally yet. Should I just be stashing all these changes, switch to master, make the small fix, switch back to profiles then reapply the stash?

任何帮助表示赞赏。谢谢

Any help is appreciated. Thanks

推荐答案


我还没准备好在本地提交更改。

"I'm not ready to commit the changes locally yet."

git中的提交是可以随意撤消,重做和重新执行的本地事情。只有当你将commit提交到需要注意的地方。

Commits in git are local things that can be undone, redone and re-re-done at will. It's only when you push the commit somewhere that you need to pay attention.

另外,本地工具(如 gitk ,并且可以对它们进行差异化处理,并可以重新分配到其他提交等等。这是一个非常强大的工具。学习使用它。

Plus, commits are visible to local tools like gitk, and can have diffs taken of them and can be rebased onto other commits, etc. It's a very powerful tool. Learn to use it.

我经常这样做:

I frequently do:

git add .; git commit -a -m 'WIP'

只是为了保存当前工作树中的所有内容我想我可能会被打断。如果我做了一些更改,我使用:

just to stash away everything in the current work tree if I think I might be interrupted. If I make a few more changes, I use:

git add .; git commit --amend

更新我的在制品提交。当我终于准备好真正的提交时,我只是:

to update my "WIP" commit in-place. When I'm finally ready for the real commit, I just:

git reset --soft HEAD~; git reset

现在我可以仔细控制最终提交的内容。

and now I can carefully control what the final commit will be.

这篇关于在Git中的分支之间未记录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆