I have two commits in my branch.
How can I pull the first from command line in my local repository?
I have two commits under branch 'foo'. With messag "xyz" and "abc" and with some numbers written "efc204e" and "33481e8" respectively
git pull
git reset efc204e
..
Related
I accidentally made the same commit twice, and then somehow merged them and now there's this commit called "Merge remote-tracking branch 'origin/lab1' into lab1" Also my local repository is apparently not synced, this seems simple but I'm stuck
Tried squashing commits into one on github desktop, but it says "Unable to squash. Squashing replays all commits up to the last one required for the squash. A merge commit cannot exist among those commits."
I know how to fix this on my local repository, but how do I remove that merge commit from github?
If that merge commit is the latest one on lab1, you can simply reset one commit earlier (make sure you don't have any work in progress):
git switch lab1
git reset --hard lab1~
git fetch
git rebase origin/lab1
git push
But you have done commits after that merge commit, then you need mark them and replay them:
git switch lab1
git branch <sha1 of the merge commit> m
git branch lab1 tmp
git reset --hard m~
git fetch
git rebase origin/lab1
git rebase --onto lab1 m tmp
git switch lab1
git merge tmp
git push
I sent a PR and someone else made some changes so it has 3 more commits and now I need to sync that PR with my local to continue working on some changes. How could I do to sync my local with the PR. Thanks
A pull request is basically just a designated branch on your fork of the repository. Update that branch (by rebasing its commits on top of those new commits) and the pull request will automatically update to show these changes.
First, you need access to the additional commits in your own fork of the project. To do so, you can add the upstream repository as an additional remote and fetch the commits from there:
git remote add <new-remote-name> <upstream-url.git>
git fetch <new-remote-name> <upstream-branch>
Then you can rebase your changes on top of the upstream changes:
git checkout <your-pr-branch>
git rebase <new-remote-name>/<upstream-branch>
git push <origin> <your-pr-branch>
You need to rebase your branch to reflect all the merged work of others in your PR. Here is how you can do this:
Let's say upstream is the name of the remote repository which you have forked, and origin is the name of your forked repository.
git pull --rebase upstream master
git push origin master
There can be merge conflicts sometime during rebasing. In that case, check the files in which conflicts are there using:
git status
The name of the files which are in red color are the files having conflicts. Resolve the conflict manually. After resolving, add the files using:
git add <filename> or //for each conflicted file
git add --all //to add all files at once
Once again check the status using the git status command. If all the files are shown in green that means they are resolved and you can now continue your rebase. Run the below command for continuing your rebase:
git rebase --continue
Once done, simply push the changes to your forked repo using:
git push -f origin master
Note: In case, you have not set the remote url of your upstream and origin, add them using following commands:
git remote add upstream <upstream-url>
git remote add origin <origin-url>
On my gihub forked repo, it is said that the master branch is 9 commits ahead of the parent repository's master branch.
When I click compare, it is shown that 0 files changed.
The reason why I have these commits:
8 commits were made to solve an issue, opened PR to the upstream repo, PR was successfully merged to the parent repo. While merging I chose the option to squash my 8 commits into 1 commit.
Then on my github forked repo page I had a message "your branch is 8 commits ahead, 3 commits behind"
I have synced my local forked repo with the upstream repo.
$ git remote add upstream https://github.com/[Original Owner Username]/[Original Repository].git
$ git fetch upstream
$ git checkout master
$ git merge upstream/master
$ git push
While merging there were no conflicts. And due to merging local/master with upstream/master 1 more commit was created.
I guessed that updating the local forked repo and pushing changes to the github repo would help to resolve the issue. But, apparently, no.
Why do I still have 8 commits ahead, if they were already merged into the parent repo? Is it because of squashing while merging PR?
How can I get rid of these meaningless commits being ahead?
I'm new to Github and I have a branch that I want to merge with the master. I couldn't merge it via git command line, its very complicated.
I tried to merge it on Github site following below documentation:
Merging a pull request on GitHub
But I got the following message:
There isn’t anything to compare!
Here's the project:
https://github.com/SumayahAlharbi/erecords
What does 4 commits behind master mean?
Update
Please check below pictures:
I thought I did the merging successfully but nothing changes!
What does 4 commits behind master mean?
It means that the master branch has 4 commits which are not present in your branch currently. You need to rebase your branch and then create a New Pull
Request which will be needed to be reviewed and finally approved so
that your branch can be merged with the master.
There isn’t anything to compare!
Check the difference between the master and your branch. Click the Compare icon in Git hub or run this
command from your local branch in Git Bash : git diff --name-only master_branch.
I just checked your repo. The changes of ExportFeature branch are already merged into the master branch, and then the merge is reverted. That's why now if you raise a pull request to merge ExportFeature into master, you would get There isn’t anything to compare!.
See the latest commits on ExportFeature which are already present in the master branch.
The reason you are seeing 4 commits behind master on ExportFeature branch is since the master branch has 4 more commits than the ExportFeature branch. If you see the total commits on ExportFeature branch, it's 7, whereas the total number of commits on the master branch is 11. If you need to do any more changes on the ExportFeature branch, you would need to get the latest changes from the master branch by running the command git pull origin master when your current branch is ExportFeature on your local git terminal.
In one of case I have created an branch and started to work on. I keep on commit & push changes in local branch but did not merge in master & neither pulled any changes from master.
Now I'm done with local branch changes. I followed derekgourlay tutorial & followed following steps to merge my project.
git fetch origin
git rebase −p origin/develop
First it game me number of conflict which was obvious but changes that I committed in my local branch those are not there after merge.
Am I missing anything. Any suggestion?
You can merge develop branch with your feature branch.
$ git checkout feature
$ git pull origin develop # pull (fetch + merge) develop branch into feature
$ git push origin HEAD # update remote/feature