0

I have four times commit to my git. See log

f1f55a9     5 hours ago     user    UI improvement   master
17114a0     2013-04-16      user    enhancement
d72934e     2012-12-24      user    enhancement
bf81a9e     2012-11-27      user    origin

I would like to be master is the oldest one like this;

f1f55a9     5 hours ago     user    UI improvement
17114a0     2013-04-16      user    enhancement
d72934e     2012-12-24      user    enhancement
bf81a9e     2012-11-27      user    origin      master

Which command should I use to change master to the oldest one? I use git 1.8 on windows 7.This is my screenshot on GitStack.

enter image description here

Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65

1 Answers1

2

If you want to reset your master branch to that oldest commit (and don't have any work in progress), you can do a:

git checkout master
git reset --hard bf81a9e

But if you have to push that new master, you will have to force the push, which can be problematic for other users having already cloned the upstream repo with a more different master history.

However, if this is purely local, you can reset master to any commit you want.


Note that what you see in the GitStack web interface is the upstream repo, not your local repo.
You can reset master locally, but you would still have to do a:

git push --force origin master

That would make the upstream repo reflects the new master, but with commit f1f55a9, 17114a0, and d72934e no longer visible: master would only reference one commit.

So make sure that won't disturb any other users before doing the push --force.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @SaiYeYanNaingAye you "can't change" what? What is missing? – VonC Sep 08 '14 at 08:16
  • @SaiYeYanNaingAye what command do you type to see the old result? `git log`? – VonC Sep 08 '14 at 08:27
  • I use GitStack for windows.It is Web UI – Sai Ye Yan Naing Aye Sep 08 '14 at 08:35
  • Can you add a screenshot of what you see? – VonC Sep 08 '14 at 08:35
  • 1
    @SaiYeYanNaingAye Before using the commands in this answer, be sure to checkout the `master` branch with `git checkout master`. – Code-Apprentice Sep 08 '14 at 08:48
  • @Code-Apprentice true, I have added that step in the answer. – VonC Sep 08 '14 at 08:49
  • @Vonc Can the others commit f1f55a9, 17114a0, and d72934e disappear? I need that versions and only change master. – Sai Ye Yan Naing Aye Sep 08 '14 at 08:53
  • @SaiYeYanNaingAye sure: if you reset `master`, those commits are no longer accessible. If you still need them, create a branch first (`git branch tmp`), then reset master. Finally push both `master` (with `--force`) and `tmp`. Remmber: GitStack displays commits accessible by a branch. If you move that branch, commits no longer accessible by that branch disappear. They might still be visible from another branch, hence the '`tmp`' suggestion. Otherwise, they are left for a while in the reflog. – VonC Sep 08 '14 at 08:55