简体   繁体   English

Git分支状态输出

[英]Git branch status output

Can someone explain this git output: 有人可以解释这个git输出:

Pulling a branch from master to run on a local node: 从master提取分支以在本地节点上运行:

> git pull origin xyz

> git status
# On branch xyz 
#Your branch is ahead of 'origin/xyz' by 22 commits.
#Changed but not updated: 
  ... lots of modified stuff

ok, we want to purge the local changes... 好的,我们要清除本地更改...

> git log | head
#commit a49b36fd6635f7dd6f72bd256231b3179920ffa4 ...

> git reset --hard a49b36fd6635f7dd6f72bd256231b3179920ffa4
# On branch xyz
# Your branch is ahead of 'origin/xyz' by 22 commits. (huh?)

nothing to commit (working directory clean)

So, if it's clean and there's nothing to commit, what can be meant by "branch ahead of origin"? 那么,如果它很干净并且没有什么可提交的内容,那么“在原产地分支”意味着什么? running "git diff" returns no output. 运行“ git diff”不返回任何输出。

git diff with no arguments diffs your workspace against the index. 不带参数的git diff您的工作区与索引相对应。

If you want to diff against a branch, tell it so: 如果要与分支进行比较,请告知:

git diff origin/xyz

When git says you're 'ahead' it means that you have unpushed changes relative to the upstream remote branch. 当git表示您“领先”时,意味着您已对上游远程分支进行了未推送的更改。 In this case it seems your upstream is 'origin/xyz'. 在这种情况下,您的上游似乎是“ origin / xyz”。 If you push then run status again, this message will go away. 如果您再次按下然后运行状态,此消息将消失。

Similarly if you git fetch then git status , if changes were fetched you will see a message stating you are behind by a number of commits. 同样,如果您先git fetch然后git status ,如果已获取更改,您将看到一条消息,指出您落后了许多提交。 If you have unpushed changes and the remote changed since you started your edits (ie. you've diverged) then you'll see you are both ahead and behind! 如果您自开始编辑以来就取消了更改并且遥控器已更改(即,您已分开),那么您将看到自己处于领先地位和落后地位!

By the way if you want to purge local changes, you can do so using git clean instead of reset --hard . 顺便说一句,如果您要清除本地更改,可以使用git clean而不是reset --hard Alternatively you can simplify your two lines into git reset --hard HEAD . 或者,您可以将两行简化为git reset --hard HEAD


EDIT if you have changes locally that you wish to throw away then you can use reset to move your workspace to the remote ref. 如果您希望在本地放弃更改,则进行编辑 ,然后可以使用reset将工作区移至远程引用。

git reset --hard origin/xyz

This will move the current branch to the same commit as origin/xyz . 这会将当前分支移至与origin/xyz相同的提交。 Note that any changed files will be blown away forever! 请注意,任何更改的文件将永远被吹走! If you have changes you wish to take with you, make sure you stash them first (or commit then cherry pick). 如果您希望更改,请确保先存储(或先提交然后再选择)。

The branch is tracking another branch as being "upstream" of it. 该分支正在跟踪另一个分支,使其处于“上游”。 This means that what you have in your branch is really new and if you want to get rid of that message, just use 这意味着您分支中的内容确实是新的,如果您想摆脱该消息,只需使用

git push

While on that branch. 在那个分支上。


If you want to never have that message pop up, then use 如果您不想让该消息弹出,请使用

git config --unset branch.xyz.merge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM