简体   繁体   English

提交到Bitbucket中团队成员的远程存储库后删除的项目更改

[英]Changes in the project deleted after commiting to a remote repository of team member in Bitbucket

I am a new git user. 我是新的git用户。 i am working with my team in a laravel web application project. 我正在与我的团队一起在laravel Web应用程序项目中工作。 First i cloned the project in my local machine. 首先,我在本地计算机上克隆了该项目。 then i made some changes. 然后我做了一些改变。 i have read and write access to the team repository in Bitbucket where there is a branch 'mybranch' beside master branch. 我对Bitbucket中的团队存储库具有读写访问权限,其中在主分支旁边有一个分支“ mybranch”。 i had to commit my changes to this mybranch. 我必须对mybranch进行更改。 In order to commit to mybrance, i switched the branch by using 为了尽我所能,我通过使用

git checkout mybranch

then i got following message 然后我得到以下消息

error: Your local changes to the following files would be overwritten by checkou t: resources/views/aview.blade.php Please commit your changes or stash them before you switch branches. Aborting

then i used following command 然后我用下面的命令

git checkout -f mybranch

then i commited the files like following 然后我像下面提交了文件

git add .
git commit -m "my changes" 
git push origin mybranch

It committed my controller and view files of the project to mybranch of the repository of bitbucket, but other configuration files of the project were not committed. 它将我的控制器和项目的查看文件提交到bitbucket存储库的mybranch,但未提交项目的其他配置文件。 More importantly, when i switched to master branch and tried to access my codes in local machine, i found all my changes are disappeared. 更重要的是,当我切换到master分支并尝试访问本地计算机中的代码时,我发现所有更改都消失了。 now i only have the project files which was cloned before from the repository. 现在我只有从存储库中克隆的项目文件。 Can anyone tell me what went wrong here and how to recover my changes again ? 谁能告诉我这里出了什么问题以及如何恢复我的更改? Thank you so much in advance ! 提前非常感谢您!

Your changes were committed to mybranch that's why they're not in the master branch. 您的更改已提交到mybranch ,这就是为什么它们不在master分支中的原因。 If you want those changes in your master branch, you can do git merge mybranch while you're in the master branch. 如果你想在你的主分支这些变化,你可以做git merge mybranch ,而你在是master分支。 Next time you encounter the error message that you posted, you can do git stash before you try to checkout the other branch. 下次遇到发布的错误消息时,可以在尝试检出另一个分支之前执行git stash Then you can just run git stash pop afterwards. 然后,您可以稍后再运行git stash pop

When you did 当你做了

git checkout -f mybranch

you told Git to force checkout mybranch , and to overwrite any local changes which would be overwritten in the process. 您告诉Git强制检出mybranch ,并覆盖将在此过程中覆盖的所有本地更改。 It appears that you have nuked some of your work, and there may not be a fix. 看来您已经取消了部分工作,并且可能没有解决方法。

Here is what you could have done to avoid this: 为避免这种情况,您可以采取以下措施:

git stash               # stash your working directory
git checkout mybranch   # switch to mybranch
git stash apply         # now bring back your working directory
git commit -m '...'     # commit your work on your branch

For future reference, be wary of your working directory as it is quite possibly the most vulnerable data. 供将来参考,请警惕您的工作目录,因为它很可能是最易受攻击的数据。 It is relatively hard to mess up with commits, but the working folder is another story. 搞砸提交相对困难,但是工作文件夹是另一回事。

With regard to the master branch, you never committed this work on that branch, and hence you won't find the changes there. 关于master分支,您从未在该分支上进行过这项工作,因此您将无法在其中找到更改。

Unfortunately, you can't recovery it back since you were not committed the changes on master and checkout to mybranch by default. 不幸的是,您无法将其恢复,因为默认情况下您没有在master和checkout上提交对mybranch的更改。

Before switching to other branches, the changes on the current branch should be committed. 在切换到其他分支之前,应先提交当前分支上的更改。 If you try to switch to another branch while the changes is not committed on the current branch, git will hint you (as you met): 如果在当前分支上未提交更改的情况下尝试切换到另一个分支,则git会提示您(如您所见):

 Your local changes to the following files would be overwritten by checkout 

But if you checkout to another branch by force ( git checkout -f ), git will discard the uncommitted changes on current branch. 但是,如果您通过强制签出到另一个分支( git checkout -f ),则git将丢弃当前分支上未提交的更改。

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

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