简体   繁体   English

提交后 git 文件和文件夹在结帐后消失[暂停]

[英]After commit git files and folder disappear after checkout [on hold]

I created a branch added few files to it, committed changes.我创建了一个分支,向它添加了一些文件,提交了更改。 Later I did checkout to master.后来我结帐给大师。 After that the files in the folder disappeared.之后文件夹中的文件消失了。 When I switched back to the same branch again I can see all the files back.Below are the steps that I followed:当我再次切换回同一个分支时,我可以看到所有文件。以下是我遵循的步骤:

1. git checkout branchName
2. vi test/test.txt
3. git add .
4. git commit -m "test commit"
5. git push
   after this step the folder contains test.txt file
6. git checkout master
   after this step the file test.txt disappears from test folder
7. git checkout branchName
   after this i can again see the file test.txt file in test folder

Kindly tell me if I am missing any steps here如果我在这里遗漏任何步骤,请告诉我

Thanks in advance提前致谢

You need to understand how GIt Checkout Command work : Once you switch to a new branch by typing您需要了解GIt Checkout Command 的工作原理:一旦您通过键入切换到新分支

$git checkout new_branch

Once you run this command it will:运行此命令后,它将:

  • Remove all the files and directories from the Working Directory( they are all stored in the repository so no worries nothing lost)从工作目录中删除所有文件和目录(它们都存储在存储库中,所以不用担心不会丢失)
  • Pull out from the repository all of the files and directories of the commit that this new branch points to.从存储库中提取此新分支指向的提交的所有文件和目录。

To recap: this will remove all the files that are referenced by commits in the master branch.回顾一下:这将删除主分支中提交引用的所有文件。 They will be replaced by the files that are referenced by the commits in the newly created branch.它们将被新创建的分支中的提交引用的文件替换。 This is so important to know and to understand.了解和理解这一点非常重要。

Note that all the commit that you will do later will be added to the active branch.请注意,您稍后将执行的所有提交都将添加到活动分支中。 so check first in which branch you are in first u can use git log --oneline --graph --all for example to show the complete graph and where the head is.所以首先检查你在哪个分支,你可以使用git log --oneline --graph --all例如显示完整的图表和头部的位置。

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

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