ReinH Git工作流程 [英] ReinH Git Workflow

查看:105
本文介绍了ReinH Git工作流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此工作流程:

http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html



在这里他提到:首先,在您的主分支(git checkout master)中,拉入最近的更改:
git pull origin master
这绝不应该创建一个合并提交,因为我们从来没有直接在master中工作。



哎呀,我只是做了。我无意中对一些文件进行了一些更改(我的主题分支)。然后我意识到我的错误 - 删除了我的主题分支。现在我想摆脱我对(主人)所做的改变,什么是正确的做法?我还没有重新发布或推迟我的更改回购,所以它是所有本地。



从本质上讲,我想拉下最新版本的主代码,只是无视我对本地主人所做的一切(这实际上是一次提交)。 如果你只是想把它扔掉,而你在你的主分支:

  git reset --hard HEAD ^  

这个命令会将您的主人的HEAD指针重置为先前的提交。 (你也可以说HEAD〜1,意思与HEAD ^相同)。更一般地说,你也可以重新设置你的主服务器与服务器的一样:

  git reset --hard origin / master  

无论主人的状态(即5人在原点之前提交,或30人在其后面提交)。这些命令中的 - hard 选项意味着工作树中的文件也将与分支头一起重置。



额外提示



如果您的情况类似于您确实希望保留更改的情况,则始终可以这样做:

  git fetch#这会从服务器获取更改,但不合并它们
git rebase origin

这将在服务器的最新变化之上重播您掌握的所有工作。



另一种选择是为主人创建一个主题分支:

  git checkout -b newfeature  

$ b然后你可以切换回master(git checkout master)并使用第一条命令将主回退一次提交。请记住,分支实际上只是存储库中提交的便利名称。例如, master 只是对该分支上最新提交的引用。你可以随意移动这些引用,并且随着你使用git更高级,你会发现自己经常这样做。



我也建议你养成这种习惯当你在玩分支时,运行 gitk --all ,这样你就可以直观地看到你在做什么。当我刚接触git时,我一直在执行这个命令。我还是...

I am using this workflow:

http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html

where he mentions: "First, and while in your master branch (git checkout master), pull in the most recent changes: git pull origin master This should never create a merge commit because we are never working directly in master."

Whoops, I just did. I accidentally committed a few changes to a couple of files to my master (vs my topic branch). I then realized my mistake - deleted my topic branch. Now I want to get rid of my committed changes (to the master), what is the right thing to do? I have not rebased yet or pushed my changes to repo, so it is all local.

In essence, I want to pull down the latest version of the master code and just disregard everything I have done to my local master (which is really one commit).

解决方案

If you just want to throw it away, while you're on your master branch:

git reset --hard HEAD^

This command will reset your master's HEAD pointer to the previous commit. (You could also say "HEAD~1", which means the same thing as HEAD^.) More generally, you can also reset your master to be the same as the server's:

git reset --hard origin/master

This will work regardless of the state of master (i.e. 5 commits ahead of origin, or 30 commits behind it). The --hard option in these commands means that the files in your working tree will also be reset along with the branch heads.

Extra tips

If you were in a similar situation where you actually wanted to keep your changes, you can always do:

git fetch             # This grabs changes from the server without merging them
git rebase origin

That will replay any work you have in master on top of the latest changes on the server.

Yet another alternative would be to create a topic branch for your work on master:

git checkout -b newfeature

Then you could switch back to master (git checkout master) and use the first command I gave to rewind master back one commit. Remember, branches are really just convenient names for commits in your repository. For example, master is just a reference to the latest commit on that branch. You can move these references at will, and as you get more advanced with git, you'll find yourself doing it fairly often.

I also recommend you get in the habit of running gitk --all whenever you're playing with branches, so you can visually see exactly what you're doing. When I was new to git, I ran this command all the time. I still do...

这篇关于ReinH Git工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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