Git:如何在提交之间来回移动 [英] Git: How to move back and forth between commits

查看:121
本文介绍了Git:如何在提交之间来回移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于Git的新手问题:



我需要在分支历史中来回移动。
这意味着,我需要将所有文件都置于旧版本中的状态,然后我需要返回存储库中的最新状态。我不需要提交。



使用SVN,它会是

  svn up -r800 

到版本800,并且

  svn up 

与存储库同步。



我知道我希望返回的提交的散列,所以我试过了

  git reset< hash> 

这似乎让我在那里。但后来我试过了

  git pull 

但抱怨冲突。



那么移动分支历史的正确方法是什么?



我在考虑SVN,所以不要犹豫,指点我一些很好的教程。请注意,我已经检查过 http://git.or.cz/course/svn.html http://www.youtube.com/watch?v=8dhZ9BXQgc4

谢谢,Ondra。

解决方案

也是前svn用户,现在在我的所有项目中都使用git。



使用git时,应该改变用于客户端 - 服务器架构的思维方式SVN。在svn中,每个更改都需要与服务器建立连接。使用git,您的repo位于工作目录中。您不需要每个回购操作的连接。



只能使用 git push git pull 与repo同步。想想像使用rsync或任何备份解决方案,使两个地方有完全相同的内容。就像连接外部备份硬盘一样,然后使其中的内容与主内容相同。这就是 git pull git push 的用法。



如果你只是想回顾历史,可以使用 git checkout 来完成。使用 git history 查看版本ID。如果您使用的是Linux,请使用 gitk 来查看修订树。在Windows中,tortoise git可以使用修订图显示它。



要回到最新版本,请使用 git checkout master 。在做任何命令之前,始终让自己做 git status 。此命令将显示您需要了解的当前回购条件的任何信息,以及您需要采取哪些措施才能使其正确。在执行 git pull git push 之前,最好确保 git status code> result包含文本工作目录clean



如果您需要将文件恢复为以前的版本,你可以用 git merge 来完成。在执行文件之前,先用 git diff 来测试它。例如: git diff rev1:rev2 filename 。它会打印出两个版本之间的任何不同。 rev1中的更改​​将被rev2中的更改所取代。所以要恢复,rev2将会比rev1更早。在满足差异结果之后,用 git merge 来完成,只需用替换 diff 合并,所有其他参数保持不变。



我希望这可以帮助你。主要的关键是看你的工作目录是你的回购。理解这将帮助你使用git来完成它的功能。祝你好运。


I have a newbie question about Git:

I need to move back and forth in a history of a branch. That means, I need to get all the files to the state they were in in some old revision, and then I need to get back to the latest state in the repository. I don't need to commit.

With SVN, it would be

svn up -r800

to get to revision 800, and

svn up

to get in sync with the repository.

I know the hash of the commit I want to get back to, so I tried

git reset <hash>

which seems to get me there. But then I tried

git pull

but that complains about conflicts.

So what's the proper way to move through the history of the branch?

I'm thinking in terms of SVN, so don't hezitate to point me to some nice tutorial. Note that I've already checked http://git.or.cz/course/svn.html and http://www.youtube.com/watch?v=8dhZ9BXQgc4 .

Thanks, Ondra.

解决方案

Well, I'm a former svn user too, and now use git for all my projects.

When using git, you should change the way of thinking from the client-server architecture that's used in svn. In svn, every change needs a connection with server. Using git, your repo is in the working directory. You don't need a connection for every repo action.

Only use git push and git pull to synchronise with repo. Think of it like using rsync or any backup solution, to make two place have exactly same content. Just like you connect external backup hard disk, then make the content in it same with the content in your main. That's the usage of git pull and git push.

If you just want to go back and forth the history, do it using git checkout. See the revision id using git history. If you're using Linux, use gitk to see the revision tree. In Windows, tortoise git can display it using revision graph.

To get back to latest revision, use git checkout master. Before doing any command, always make yourself do git status. This command will display anything you need to know about current repo condition, and what action that you need to do to make it right. Before do git pull and git push, it's better to make sure that git status result is contain text working directory clean.

If you need to revert a file to it's previous revision, you can do it with git merge. Before doing it to a file, test it first with git diff. Ex: git diff rev1:rev2 filename. It will print out any different between two revision. Change in rev1 will be replaced by the changes in rev2. So to do revert, rev2 will be the older than rev1. After you satisfy with the diff result, do it with git merge, just replace diff with merge, all other parameters stay the same.

I hope this helps you. The main key is to see that your working dir is your repo. Understanding this will help you use git to it's full capability. Good luck.

这篇关于Git:如何在提交之间来回移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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