什么是相当于 TFS 命令搁置/取消搁置的 Git?樱桃?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3069979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what's the Git equivalent of TFS commands shelve/unshelve? cherry-pick?
提问by MatthieuGD
I found that the shelve/unshelve commands in TFS are very handy and very simple to use. What's the equivalent in Git ?
我发现 TFS 中的搁置/取消搁置命令非常方便且使用起来非常简单。Git 中的等价物是什么?
here's the scenario in TFS :
这是 TFS 中的场景:
- I made changes in the trunk
- I shelve : the change set is saved on the server (with a label) and I get the source back before the changes
- I work in the trunk
- Someone can unshelve : get the change set in his workspace
- 我在后备箱中进行了更改
- 我搁置:更改集保存在服务器上(带有标签),我在更改之前取回源
- 我在后备箱工作
- 有人可以取消搁置:在他的工作区中获取更改集
I know that there's a command call cherry-pick but i"m not sure of the workflow and if it fits the need.
我知道有一个命令调用cherry-pick,但我不确定工作流程是否符合需要。
回答by Cascabel
What you describe is similar to git stash
, except since with git you have your own repository (not just a single one on a server), only you can get that change set back.
您所描述的类似于git stash
,除了因为使用 git 您拥有自己的存储库(不仅仅是服务器上的单个存储库),所以只有您才能恢复该更改。
The general idea is:
总体思路是:
# do some stuff
vim foo/bar.c
# stash away your changes
git stash
# do some other things...
# retrieve your changes
git stash pop
If you wanted someone else to have access to this changeset, you'd want to instead commit it to a working branch:
如果您希望其他人可以访问此变更集,您需要将其提交到工作分支:
# make yourself a branch
git checkout -b temp-featureA
# commit to it
git add foo/bar.c; git commit
# now you push this branch (or they could just fetch straight from you)
git push origin temp-featureA
# Now, in someone else's repo:
# Fetch updates
git fetch origin
# Make a branch tracking the remote branch
git branch temp-featureA origin/temp-featureA
# Either check it out:
git checkout temp-featureA
# or cherry-pick it, to apply the changes somewhere else:
git cherry-pick temp-featureA
# or, if it's multiple commits, rebase it!
git rebase --onto my-branch start-of-featureA temp-featureA
回答by Neall
What you want to do is accomplished with plain old branching in git.
你想要做的是在 git 中使用普通的旧分支来完成。
From a nice StackOverflow answerby JaredPar:
从一个不错的StackOverflow的答案被JaredPar:
Shelving is a way of saving all of the changes on your box without checking in. The changes are persisted on the server.
搁置是一种无需签入即可保存盒子上所有更改的方法。更改将保留在服务器上。
This is analogous to committing to a branch and pushing it to a server in git.
这类似于在 git 中提交到一个分支并将其推送到服务器。
How to do it:
怎么做:
Let's say you're working on the "master" branch and you decide to implement feature X. You get a good start on it, but then your boss tells you that feature Y needs implemented as soon as possible. Phil in the next cube over volunteers to finish feature X while you do feature Y. Here's what you do:
假设您正在“主”分支上工作,并且您决定实现功能 X。您已经有了一个良好的开端,但随后您的老板告诉您,功能 Y 需要尽快实现。菲尔在下一个立方体中自愿完成特征 X,而你做特征 Y。这是你要做的:
Make a new branch and switch to it:
创建一个新分支并切换到它:
$ git checkout -b feature-x
Commit your changes:
提交您的更改:
$ git add filethatyouchanged.cc
$ git commit -m 'partial implementation of feature X'
Push it to a server that Phil can see:
将其推送到 Phil 可以看到的服务器:
$ git push origin feature-x
Go back to the master branch (which has not changed):
回到 master 分支(没有改变):
$ git checkout master
You might also want to proactively create a new branch for feature Y:
您可能还想为功能 Y 主动创建一个新分支:
$ git checkout -b feature-y
Phil can now pull down your feature X work and pick up where you left off:
Phil 现在可以撤下您的功能 X 工作并从您中断的地方继续:
phil$ git fetch origin
phil$ git checkout -t origin/feature-x
回答by VonC
git stashis a bit similar, except it is limited to yourworking tree.
git stash有点类似,只是它仅限于您的工作树。
In a DVCS, to achieve that kind of workflow, you need to:
在 DVCS 中,要实现这种工作流程,您需要:
- commit your current changes in a new branch
- checkout the original branch where you can go on, with none of the changes you had introduced (but committed in the new branch)
- push that new branch to a bare repo
- allow another developer to pull that new branch and merge it to his current branch.
- 在新分支中提交您当前的更改
- 签出您可以继续的原始分支,没有您引入的任何更改(但在新分支中提交)
- 将该新分支推送到裸仓库
- 允许另一个开发人员拉取该新分支并将其合并到他的当前分支。
Another way would be to let the other developer fetch your branch (where you have committed that special set of changes), and cherry-pick it, but that is not recommended, for cherry-picked commits are hard to track.
另一种方法是让其他开发人员获取您的分支(您在其中提交了一组特殊的更改),然后挑选它,但不建议这样做,因为挑选的提交很难跟踪。