本文介绍了理解git fetch然后合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从svn的背景来看,我有这个问题:



(相当于 svn状态的git是什么-u



据我所知,您可以:

  git fetch 
git log ..origin / master

但是,我猜测 origin / master 部分取决于分支?如果我正在跟踪一个远程分支,它不一定是主人?



我也不明白 git merge origin / master 正好。我猜这只是意味着 git fetch 从远程抓取了更改,并将它们作为原点/主数据放入git数据库系统中,而我只是主人?如果我提取了更改,检查完成了什么,是否为这些更改感到震惊并且不想合并?我如何基本放弃他们?

解决方案

git fetch



git fetch 从远程存储库获取更改并将其放入存储库的对象数据库中。它还从远程存储库获取分支,并将它们存储为 远程跟踪分支

当你读取git时,它会告诉你它在哪里存储每个分支在远程仓库中的地址。例如,您应该看到类似于

  7987baa..2086e7b master  - >起源/主

取数时。这意味着'origin / master'存储'master'位于'origin'仓库中的位置。



如果您检查 .git / config file,你会看到以下片段:

 
[remoteorigin]
url = git: //git.example.com/repo.git
fetch = + refs / heads / *:refs / remotes / origin / *



这个(其他)意味着源远程的任何分支'A'('refs / heads / A')将被保存为'origin / A'('refs / remotes / origin / A')。

git log ..origin / master



正如你可以看到'origin / master'是起源的主人。如果你在(默认)'master'分支上,那么 git log ..origin / master ,相当于 git log HEAD..origin / master ,当'master'分支相当于 git log master..origin / master 时,它会列出'master'上的所有提交'分支在远程仓库中,并且不在本地主分支中,您可以在其中工作。



现代git中的更通用的版本(假设存在上游/ )可以简单地使用

  $ git log .. @ {u} 

(这里 @ {u} @ {upstream}的同义词, ,参见 manpage指定版本和范围)。
$ b

git merge origin / master



git merge 用于连接两行历史记录。如果其中一方自上次分支点以来没有做任何工作(因为合并基础),则情况要么是快进(您所在的分支只是更新到分支的顶端) (合并)或最新(没有什么新的合并,你所在的分支保持不变)。



git fetch 后跟 git merge origin / master ,当在'master'分支时,相当于发行

  $ git pull 






如果你不想合并,你不需要。请注意,您可以使用例如 git reset --hard HEAD @ {1} 返回并放弃 git pull 的结果,如果您不喜欢它。

Coming from an svn background, I had this question:

git equivalent of svn status -u

(what is the git equivalent of svn status -u)

And I understand, you do:

git fetch
git log ..origin/master

But, I'm guessing the origin/master part depends on the branch? It wouldn't necessarily be master if I was tracking a remote branch?

I also don't understand the git merge origin/master precisely. I'm guessing that just means that git fetch grabbed the changes from the remote and put them into the git database system as origin/master and I'm in just master? What if I fetched changes, check what was done, am horrified by the changes and don't want to merge? How do I basically abandon them?

解决方案

git fetch

git fetch grabs changes from remote repository and puts it in your repository's object database. It also fetches branches from remote repository and stores them as remote-tracking branches.

When you are fetching git tells you where it stores each branch on remote repository it fetches. For example you should see something like

   7987baa..2086e7b  master -> origin/master

when fetching. This means that 'origin/master' stores where 'master' is on 'origin' repository.

If you examine .git/config file, you would see the following fragment:

[remote "origin"]
        url = git://git.example.com/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*

This (among others) means that any branch 'A' ('refs/heads/A') in origin remote (repository you cloned from) would be saved as 'origin/A' ('refs/remotes/origin/A').

git log ..origin/master

As you can see 'origin/master' is 'master' in origin. If you are on (default) 'master' branch, then git log ..origin/master, which is equivalent to git log HEAD..origin/master, which when on 'master' branch is equivalent to git log master..origin/master would list all commits that are on 'master' branch in remote repository and are not in local 'master' branch where you do your work.

The more generic version in modern git (assuming that upstream / tracking information exists) would be to use simply

$ git log ..@{u}

(Here @{u} is synonym for @{upstream}, see gitrevisions manpage).

git merge origin/master

git merge is used to join two lines of history. If one of sides didn't do any work since last branching point (since merge base), the situation is either fast-forward (the branch you are on is simply updated to the tip of the branch you are merging), or up-to-date (there is nothing new to merge, and the branch you are on stays unchanged).

git fetch followed by git merge origin/master, when on 'master' branch, is equivalent to issuing

$ git pull


If you don't want to merge, you don't need to. Note that you can use e.g. git reset --hard HEAD@{1} to go back and discard result of git pull if you don't like it.

这篇关于理解git fetch然后合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 02:38