Reputation: 20
So I want to bring commits of another branch till specific date only and I want them to appear on my branch as if they were my branch's commit. So when I push my branch to github those commits should appear on top.
For ex: I want to bring 'main' branches commits to my 'dev' branch till let's say 2021.10.12 and when I push my branch to GitHub the commits must appear till 2021.10.12.
How is it possible?
So I tried checkout main@{'date'}
but it is creating new pointing address, asking if I would like to publish it as new branch. But that is not what I want
Upvotes: 1
Views: 203
Reputation: 51860
One way is :
# spot the commit on 'main' which you want to get,
# create a 'wip' branch on that commit:
git switch -c wip <commit>
# rebase that branch on top of your dev branch:
git rebase dev
# move your dev branch up to that point:
git checkout dev
git merge --ff-only wip
# you may now drop that wip branch:
git branch -d wip
# and push your dev branch:
git push origin dev
About the first command :
main@{'date'}
will not look for "the last commit before 'date'
", it will look into your local reflog (a history of what happened on your local repo), and get "the state main
was in at 'date'
on your computer".git pull
for a long time), and you ran git pull
today, main@{yesterday}
will translate to "the 3 month old main
".If you want to get "the state of upstream main at 'date'
", you can either:
main
)git log
:git log --until="<date>" -1 main
# or
git log --graph --oneline --until="<date>" main
# and copy the hash from the first line
# or
git log --graph --oneline main
# figure out up to what commit you want to include
# and copy the sha of that commit
Upvotes: 1