如何列出仅在 git 中的当前分支中所做的所有未提交的更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17319517/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:25:48  来源:igfitidea点击:

how to list all uncommitted changes made only in current branch in git

gitbranchgit-commitgit-checkout

提问by user2373881

I am a newbie to git initially i used to work only on master branch then i read a little about git branching and i was amazed by it power so i started using branches in my workflow

我是 git 的新手,最初我只在 master 分支上工作,然后我读了一些关于 git 分支的知识,我对它的强大功能感到惊讶,所以我开始在我的工作流程中使用分支

when i started with branching my master branch was clean nothing to commit. Then I created new branch feature1

当我开始分支时,我的主分支是干净的,没有什么可提交的。然后我创建了新的分支feature1

git checkout -b feature1

i made my changes in branch feature1added some js and css files . Then i created another branch from master branch without committing changes made to branch feature1like so :

我在分支feature1 中进行了更改,添加了一些 js 和 css 文件。然后我从 master 分支创建了另一个分支,而不像这样提交对分支feature1所做的更改:

git checkout master
git checkout -b feature2

i added some more code in feature2branch and added some new css files and then again i created another branch feature3from master with committing changes in branch feature2like this :

我在feature2分支中添加了更多代码并添加了一些新的 css 文件,然后我再次从 master创建了另一个分支feature3,并在分支feature2 中提交更改,如下所示:

git checkout master
git checkout -b feature 3

I added some new code in feature3branch with 1 new css file . now when i did :

我在具有 1 个新 css 文件的feature3分支中添加了一些新代码。现在当我这样做时:

git status

I got list of all files which i modified but not committed in all the 3 branches . I was expecting that i will get only list of file modified in current branch i.e branch feature3, now i don't remember which files I created in which branch .

我得到了我修改但未在所有 3 个分支中提交的所有文件的列表。我原以为我只会得到当前分支中修改的文件列表,即分支feature3,现在我不记得我在哪个分支中创建了哪些文件。

Can anyone please help me to list only files i created or modified in particular branch and commit them. to respective branches .

任何人都可以帮助我仅列出我在特定分支中创建或修改的文件并提交它们。到各自的分行。

For e.g

例如

list all files modified or created in feature1branch and commit them to feature1branch and do this with all 3 branches.

列出在feature1分支中修改或创建的所有文件,并将它们提交到feature1分支,并对所有 3 个分支执行此操作。

I also want to know how i can create a branch from master branch without getting other files which are modified in other branch but not committed . i.e i want the new branch to be exact clone of master with noting to commit.

我还想知道如何从 master 分支创建一个分支,而无需获取在其他分支中修改但未提交的其他文件。即我希望新分支是 master 的精确克隆,并注意提交。

采纳答案by Mark Fisher

As mentioned by @abeaumet if you create files but don't commit them, you can't track them when you change branches.

正如@abeaumet 所提到的,如果您创建文件但不提交它们,则在更改分支时无法跟踪它们。

This is because they are in your working tree and not your git repository. Your working tree is effectively a checked out version of your repository, plus any changes you're currently making. Moving around branches does not delete these untracked files, git is leaving them in your working tree so they don't get deleted.

这是因为它们在您的工作树中,而不是您的 git 存储库中。您的工作树实际上是您的存储库的检出版本,以及您当前所做的任何更改。移动分支不会删除这些未跟踪的文件,git 会将它们留在您的工作树中,因此它们不会被删除。

Read some of the articles linked in this questionto understand the difference between your repository and the working tree.

阅读此问题中链接的一些文章,以了解您的存储库和工作树之间的区别。

回答by Balog Pal

Just launch gitk --alland you can inspect all your branches, changes, whatever. Select a point and right-click on another and from top of the menu you get diff of two versions.

只需启动gitk --all,您就可以检查所有分支、更改等。选择一个点并右键单击另一个点,然后从菜单顶部获得两个版本的差异。

A branch in git is just a 'label' on a commit. If you create a branch on top of the master, it is as perfect "clone" as you can get. Though really it's just a 41 byte file containing the same hash.

git 中的分支只是提交上的“标签”。如果你在 master 之上创建一个分支,它就像你能得到的那样完美的“克隆”。虽然实际上它只是一个包含相同散列的 41 字节文件。

I think you should familiraize yourself a bit with what is what, from the description I could not deduce what you did and especially what you're after.

我认为你应该熟悉一下什么是什么,从描述中我无法推断出你做了什么,尤其是你在追求什么。

回答by aymericbeaumet

It's not possible to determine on which branch a file was created if you didn't commit it.

如果您没有提交文件,则无法确定文件是在哪个分支上创建的。