我怎样才能检查一个分支,同时确保我的当前分支没有任何更改结转? [英] How can I checkout a branch while ensuring that none of my current branch's changes are carried over?

查看:111
本文介绍了我怎样才能检查一个分支,同时确保我的当前分支没有任何更改结转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想切换分支并让git 总是设置工作目录的内容以反映我要切换到的分支的状态。我遇到了此处列出的行为 https://web.archive.org/web/20160331103129/http://www.gitguys.com/topics/switching-branches-without-committing - git正在作出决定**是否将某些文件从与我当前分支关联的工作目录传送到我切换到的分支。



** 这似乎与 https://www.atlassian.com/git/tutorials/using-branches :检出分支会更新工作目录中的文件以匹配存储在该分支中的版本......



在某些情况下,我不想git做出决定 - 我只希望Git使工作目录匹配新分支的状态。不过,我不想失去任何改变。我愿意承诺或提前存储。

可能吗?

解决方案


在您的工作树或索引中保留未提交的更改,直到您告诉git将其提交到哪里。
git add git checkout git reset 都有一个 - patch 选项。工作流程是,做需要做的事情,并在需要录制的地方录制它们是独立的任务。通常情况下,你会发现自己正在有效驾驶 - 通过修正错误,在那里你发现一个完整的混乱,通常是我 剩下的问题是,正在做这项工作,做文书工作,但你直视着工作,并确切知道需要做什么。



git方式 1 是Do It。在你的工作树中得到一切正确的结果(这可能涉及到一些探索性的分支本身)。然后构建你将会拥有的提交系列。如果您确切知道您一直在做什么,那么您就可以在第一时间建立起来。


这是重要的部分。这就是专业,可发布的工作。让人们了解的是,git的意义至少与之前的混乱部分相同。

1 他说:git的方式,好像只有一个 lol


I want switch branches and have git always set the working directory contents to reflect the state of the branch I'm switching to. I'm experiencing the behaviors stated here https://web.archive.org/web/20160331103129/http://www.gitguys.com/topics/switching-branches-without-committing - git is making a decision** on whether to carry certain files from the working directory associated with my current branch to the branch I switch to.

** This seems to conflict with what's stated here https://www.atlassian.com/git/tutorials/using-branches: "Checking out a branch updates the files in the working directory to match the version stored in that branch..."

In some cases I don't want git to make a decision - I just want Git to make the working directory match the state of the new branch. However, I don't want to lose any changes. I'm willing to commit or stash prior.

Possible?

解决方案

Uncommitted changes remain in your worktree or index until you tell git where to commit them.

git add, git checkout and git reset all have a --patch option. The workflow is, doing what needs doing and recording it where it needs recording are separate tasks. Often enough you find yourself doing effectively drive-by bugfixing, where you find a complete mess someoneusually me left and the issue is, there's doing the work, and doing the paperwork, but you're staring right straight at the work and know exactly what needs doing.

The git way1 is, Do It. Get it all correct in your worktree (this may involve a bit of exploratory branching itself)

  • and then construct the commit series you'd have constructed in the first place if you'd known exactly what you were doing all along.

That's the important part. That's what makes professional, publishable work. What trips people up is, git's meant at least as much for the messy part that comes before that.


1hahaha he said "the git way", as if there were only onelol

这篇关于我怎样才能检查一个分支,同时确保我的当前分支没有任何更改结转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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