Reputation: 12449
Major changes gone. And for no apparent reason.
Firstly, I made my own branch my_branch form feature_branch.
I made some changes, and committed them locally.
Later I needed to pull in some changes made by others on feature_branch. I did this with rebase.
Then I pushed my_branch to the server using force.
So far so good.
Then I did more changes, committed them, pulled feature_branch from server, rebased (for the second time), and my changes are gone. I have the rebase logs and history logs. This is what I just didL
Do some work.
$ git status
-> on my_branch with some changes.
$ git add . // add new files and updated files.
$ git commit -m "message"
$ git status
-> on my_branch, nothing to commit
$ git push --force // send my changes to my_branch on the server.
$ git checkout feature_branch
$ git pull // get latest changes from the server.
$ git checkout my_branch
$ git rebase feature_branch // this should merge my changes, not overwrite them!
-> bunch of merge messages and one conflict.
-> I fixed the one conflict.
Now at least some of my major changes are gone. The rebase command ($ git rebase feature_branch" has overwritten my changed (and committed) files with files from original for no apparent reason. We are talking several hundred lines of code. I have not done $ git rebase --continue yet, as I noticed it has lost my work.
If I look in bitbucket at my_branch which I pushed right before I did the rebase command, I see my changes which I pushed up. But they are missing locally since the rebase command.
What could have gone wrong?
NOTE: no one except me has modified my_branch.
I guess I have three options now.
1) wipe my local git database, and try to restore from time machine.
2) try git merge --abort and hope.
3) try to get my_branch from the server again. I don't know how to do this, other than to delete my local git directory, and clone from scratch, then checkout the branch.
Any suggestions?
Here is a log of the offending rebase:
git rebase feature_branch
First, rewinding head to replay your work on top of it...
Applying: <some old commit message1>
Using index info to reconstruct a base tree...
M somefile1
M somefile2
M somefile3
.git/rebase-apply/patch:160: trailing whitespace.
"xxx-keyspace-configs": [
.git/rebase-apply/patch:485: trailing whitespace.
.git/rebase-apply/patch:1258: new blank line at EOF.
+
.git/rebase-apply/patch:1299: new blank line at EOF.
+
.git/rebase-apply/patch:1341: new blank line at EOF.
+
warning: squelched 1 whitespace error
warning: 6 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging somefile1
Auto-merging somefile2
Auto-merging somefile3
Auto-merging somefile4
Applying: <some old commit message2>
Using index info to reconstruct a base tree...
M somefile1
M simefile2
M somefile3
M somefile4
Falling back to patching base and 3-way merge...
Auto-merging somefile4
CONFLICT (content): Merge conflict in somefile4
Auto-merging somefile3
Auto-merging somefile2
Auto-merging somefile1
error: Failed to merge in the changes.
Patch failed at 0002 xxx
The copy of the patch that failed is found in: .git/rebase-apply/patch
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
If I get back to the state before the rebase, and do it again, I'll lose my changes again.
=== update ===
$ git reflog engage-swh
c051e4f4b (origin/my_branch, my_branch) my_branch@{0}: commit: <my last commit message>
b9275d1ae my_branch@{1}: commit: <my second from last commit message>
30a24608b my_branch@{2}: rebase finished: refs/heads/my_branch onto 732a052fd4e0a6c171b52acb84ddaf16d27956c1
11c60cd90 my_branch@{3}: commit: <my first commit message>
1b811e4b2 (feature-2019R07) my_branch@{4}: branch: Created from feature-2019R07
If I look at say file6 in bitbucket for branch my_branch, then look what I have locally directly after the rebase, all the lines I added are gone. The local version is the same as the version before I made my changes. All my changes are on the remote. The file which has been "overwritten" is not one which was merged (i.e. not in the output above)
I just tried to do
$ git merge --abort
I an attempt to get my lost work back.
This results in:
fatal: There is no merge to abort (MERGE_HEAD missing).
I guess this leaves me with two options, restore a backup from time machine, or delete my project dir, clone the project again, and checkout my_branch. The question is, how do I rebase feature_branch without it overwriting my changes again? I assume I cannot merge, as I rebased originally.
==== update 2 ====
I just tried:
$ git log --oneline --graph --decorate
As suggested by padawin
It shows a very long list of commits by all the people who are working on feature_branch branch, along with all their branches off of of this. There are no errors or anything which gives a clue. Here are the first few lines:
* a84d5dcbd (HEAD) my first commit message.
* 139d71db8 (origin/feature_branch, feature_branch) made xxx in_active
* bedea7520 Merge branch 'feature_branch' of https://bitbucket.org/xxx/xxx-parent into feature_branch
|\
| * b4c06d0c8 Merge branch 'feature_branch' of https://bitbucket.org/xxx/xxx-parent into feature_branch
| |\
| * | 7996ca962 Release Prep
* | | 76aaddfcf system config update
| |/
|/|
=== update ====
I tired to finish the rebase, even though my work has been "overwritten". I fixed the one file which was in conflict, did "$ git add ." to mark it fixed, then did "$ git rebase --continue".
I now get a bunch more errors:
$ git rebase --continue
Applying: <one of my commit messages>
Applying: refactored merger, added update
Using index info to reconstruct a base tree...
M somefile1
M somefile2
M somefile3
Falling back to patching base and 3-way merge...
Auto-merging somefile3
Auto-merging somefile2
Auto-merging somefile1
CONFLICT (content): Merge conflict in somefile1
error: Failed to merge in the changes.
Patch failed at 0003 refactored merger, added update
The copy of the patch that failed is found in: .git/rebase-apply/patch
Upvotes: 0
Views: 3239
Reputation: 4476
A few things:
git push --force
?As you are the only one who worked on the branch, look at the reflog of your branches:
git reflog my_branch
Run some logs to find the commits you've lost
As per the following discussion, you had a conflict, and you are now in the middle of a rebase. You then need to stage any unstage changes that you want applied in the commit that git rebase
is trying to apply, then run git rebase --continue
to carry on with the rebase.
Upvotes: 2
Reputation: 12449
OK, after a lot of pain, I think I know what the problem is. Rebase, after it has been used a few times, works in stages. during these stages, you temporarily "lose" your work until it catches up in a later stage. I had no idea this happened - I thought all was lost.
Upvotes: 0