For example, I am working on branch1 and I want to 'git pull' code from branch2. However, I 'git pull' code from branch3 instead of branch2. How can I redo the 'git pull' command? (delete the code from branch2)
Asked
Active
Viewed 217 times
1
-
2just `git reset --hard sha` with sha the commit it of branch1 before pull – Ôrel Dec 18 '21 at 09:49
-
3A pull is just a fetch + a merge. Look for how to undo a merge. – Schwern Dec 18 '21 at 10:27
-
Do you confuse `git pull`, that syncs with a *remote repository* with `git switch` that changes branches? I down voted because [No research](http://idownvotedbecau.se/noresearch/) – Timothy Truckle Dec 18 '21 at 19:05
2 Answers
1
If you just pulled, as described in "Undo git pull
, how to bring repos to old state", a simple git reset --hard custom-branch@{1}
should be enough, assuming you have no work in prigress (or it would be lost, erased by the reset --hard
)
You can then git fetch
, and git merge origin/anyBranchYouNeed
, to make the pull you want.

VonC
- 1,262,500
- 529
- 4,410
- 5,250
1
You can use
git reset --hard <commit-id>
(kindly commit your code before that, --hard
will make you loose the uncommitted changes)

Peter Csala
- 17,736
- 16
- 35
- 75

Kajal Kumari
- 11
- 3
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 20 '21 at 02:28
-