Reputation: 5167
This is the first time I am contributing to an open source project and I have this git issue. I forked the repo originally then deleted it and then re forked it. I checked out a dev branch from my forked master and did some work and now I want to create a PR to the main repo. But it says entirely different commit histories.
I tried the below steps but did not help me
git remote add upstream https://github.com/some_user/some_repo
git fetch upstream
git checkout master
git reset --hard upstream/master
git push origin master --force
Any assistance on this will be appreciated
git log -n10 upstream/master returns below snapshot
git log -n10 origin/dev returns below snapshot
git log -n10 origin/master returns below snapshot
Upvotes: 1
Views: 326
Reputation: 18834
Based on the second screenshot you posted, it seems like you followed the following steps:
You when to either the fork or the original GitHub repo, then download a zip of it, you did your changes, an that did git init
, and forcefully pushed this to your fork.
What basically happened is that by the process of doing this, you only copied the files to your fork, and not the full history.
Since now we know what happened, we can start fixing the issue, and since the original repository isn't very busy with traffic, it becomes easier to fix now.
Because we want to keep the original files, but merge the history back in, we need to do the following steps:
git clone https://github.com/your_name/your_fork
.git
directory.git status
, this should show only the files you changed depending on the base state 1git add .
git commit -m "Adding my feature"
(I suggest you use a more descriptive commit message)git push
Now, go to the original GitHub repository, and try to make a PR there, it should be fine now.
1. If git status does not show any files changed, its probably because you accidentally copied the .git
directory from your backup
Upvotes: 2