-1

On a remote feature branch there are many commits. My local copy of the same branch is out-dated and I would like to update it with the remote feature branch. However, the final commit of that remote branch is problematic, and I want to disregard it during the update. How should I proceed while on my local copy of the branch?

Note:

My local branch is not the same as the remote branch. I had made a copy for myself with a different branch name.

Rebel
  • 472
  • 8
  • 25

4 Answers4

2

If you want to rebase your local branch with the penultimate commit of the remote branch, just checkout the local branch and do:

git rebase $remote/${remote_branch}^1

That is, if the local branch is called feature, the remote branch is called rfeature, and the remote is called origin, you would do:

git checkout feature
git fetch origin   # make sure things are up-to-date
git rebase origin/rfeature^1
William Pursell
  • 204,365
  • 48
  • 270
  • 300
1

Get on your local branch if you aren't already. Say

git fetch
git merge origin/otherBranch~1

That merges the other branch, but without its problematic last commit, into your branch.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

You cannot really ignore the last commit when you pull from what I know. But you can pull everything and then change to the commit you want like this :

git checkout COMMIT_ID
0

I would recommend do not discard the last commit but instead revert it. With this approach you will not to have to force the remote branch when you have to push it.

git pull --rebase
git revert HEAD
FarKorE
  • 31
  • 2