-
Notifications
You must be signed in to change notification settings - Fork 3
Temp Branch on an Earlier Commit
Folds edited this page Jul 5, 2017
·
5 revisions
GitKraken offers three options for resetting a branch to a previous commit. All three of these options change which commit is the highlighted commit in the "Commit Graph" portion of the user interface:
- Soft - keep all changes
- Mixed - keep working copy, but reset index
- Hard - discard all changes
If what you want to do is:
- keep all existing commits in the repository,
- change which commit is the highlighted commit in the "Commit Graph" portion of the user interface, and
- swap out the contents of the working directory to match the highlighted commit,
none of these three choices are appropriate.
Instead, create a temporary new branch at the highlighted commit. For example, you might want to do this as part of the following scenario:
- Suppose you have a folder (where you really do your work) that is separate from the folder that Git thinks is your working directory. When you are ready to check stuff in, you copy the updated files and subfolders from "where you really do your work" to Git's working directory. When you need to get an old copy of a file, you can use this procedure to do so.
- Suppose you are working in a branch, such as
dev
. -
Check in a commit (
A
), in the working branch. By default,dev
's head will now point toA
, andA
will now be the highlighted commit. -
Check in another commit (
B
). By default,dev
's head will now point toB
, andB
will now be the highlighted commit. -
Decide that you would rather have
A
thanB
, but want to keepB
in thedev
's mainline. This scenario assumes that you do not have any unsaved work that you might need tostash
. - In GitKraken's "Commit Graph" portion of the user interface, right-click on commit
A
. Choose "Create branch here". Create a temporary branch, such astemp
.dev
will still exist, and will still point toB
. The newtemp
branch will become the new working branch. The contents of the working directory will be updated to match commitA
, andA
will now be the highlighted commit. - Copy the relevant files from Git's working directory to the place where you really do your work.
- Right-click
dev
's branch label, and checkoutdev
.dev
's head still points toB
, andB
is now highlighted.temp
still exists, and its head still points toA
. - Right-click
temp
's branch label, and deletetemp
. GitKraken will warn you that 'This is a destructive operation, are you sure you want to delete "temp"?'. Confirm the delete. Although you will not be able to use "Undo" to re-createtemp
, it is easy enough to re-create thetemp
branch manually if you have to. After all, all of its contents are part of the still-extantdev
branch. - Copy the relevant files from the place where you really do your work, back to Git's working directory.
- Stage, name, optionally describe, and save a commit (
C
) that has the same contents as commitA
.dev
's head now points toC
, andC
is now highlighted.
Voila!