#modify git history

1 messages · Page 1 of 1 (latest)

fleet vortex
#

hello I am maintaining a repository on github which I rebased last week, I am currently trying to undo this rebase to restore the commit history but I am unable to achieve this

grizzled haloBOT
#

<@&987246964494204979> please have a look, thanks.

grizzled haloBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

fleet vortex
#

I have made a seperate branch which I called test and hard reset to the commit d3dfe5b364d379dda65997036bc2edd154811350 right before the rebase

#

this is the currenty history on the original dev branch:

#

the last commit of #42 is the state I was able to restore on my test branch

cunning egret
#

hi

fleet vortex
#

HEY

#

now if I want to move any higher up the commits I wipe this entire history because of the rebase

#

is there any way to just exclude that one rebase from the history and keep the original commits

cunning egret
#

yeah

#

by using rebase interactive

fleet vortex
#

i found this aswell so far

#

ok wait

#

let me pull up my history

#

I found that I can do "git rebase -i HASH" where hash is the hash of the commit of the rebase?

#

but I dont know what todo inside the window to achieve this

cunning egret
#

before we start make sure you have a core.editor property in your git global config

fleet vortex
#

what is that for?

#

and what value does it need

cunning egret
#

is to help you change the history

#

you'll get your commits written on a file with some tips

#

you change the file, save it and close the editor

fleet vortex
#

where and how do I add this property, is it .git/config ?

cunning egret
#

no

fleet vortex
#

oh wait global config, one moment let me figure this out

cunning egret
#

do you have at least notepad++?

fleet vortex
#

i have a git bash, notepad++ vim

#

whatever I need

cunning egret
#

git bash will open an editor in terminal, you need to be aware of how to save it when you finish

fleet vortex
#

i assume :wq

cunning egret
#

im windows user

fleet vortex
#

alright, I'll just use the tools you are familiar with because I dont know how to solve this and ive been stuck for 3 hours

#

which tools do you use I'll get those then instead

cunning egret
#

install notepad or something equivalent

fleet vortex
#

ok got that

cunning egret
#

are you on windows ?

fleet vortex
#

yes sir

cunning egret
#

use powershell

fleet vortex
#

opened

cunning egret
#

check your git global config with git config --global -l

fleet vortex
#
[email protected]
user.name=hawolt
user.signingkey=redacted
commit.gpgsign=true```
alright theres no core.editor
grizzled haloBOT
cunning egret
#

that means you don't have a config for core editor

fleet vortex
#

what value does it need

#

i assume I just do git config --global core.editor xyz

cunning egret
#

no

#

the value next to core.editor

#

should be inside quotes "<value>"

fleet vortex
#

yeah but what value do I have to put?

cunning egret
#

check this example

fleet vortex
#

oh this config is

#

okok i get what this config is for

#

let me set it to notepad++

#

ok done

#

got it configured to notepad++

fleet vortex
#
git config --global -l
[email protected]
user.name=hawolt
user.signingkey=redacted
commit.gpgsign=true
core.editor=C:/Program Files/Notepad++/notepad++.exe
grizzled haloBOT
cunning egret
#

now in your git repo

#

use git rebase -i

#

you have to define the number of commits

fleet vortex
#

let me put my test branch up to date with dev

cunning egret
#

like this

fleet vortex
#

so i dont mess anything up

#

one minute

cunning egret
#

like this git rebase -i HEAD~2

fleet vortex
#

ok wait theres alot of commits

#

i need to figure out how many it is

cunning egret
#

if you have merges the command would need additional keyword

fleet vortex
#

theres merges from pull requests yes

#

maybe its easier if i just link it?

#

so i dont exclude something that might be important

#

since I dont know whats needed

cunning egret
#

if you have merges and want to manipulate them as well

fleet vortex
#

theres been merges from various pull requests

#

I dont want to manipulate those

#

I only want to get rid of the rebase I did

#

last week

cunning egret
#

then no need to touch them

#

let me see the repo

fleet vortex
#

check the test branch

#

thats where I do it on

#

the rebase happened here with fix game launching

cunning egret
#

you want to go back there ?

fleet vortex
#

wait mabye im even using wrong wording

#

if you click on #42 for example

#

it has alot of commits

#

i want them to be visible in the history

#

rather than just one commit that sums it all up

#

i mangaged todo it to the point of the last commit in #42

cunning egret
#

ahaa

fleet vortex
#

but if i go any further

#

it goes back to this state

#

because something happened? i think it was a rebase

#

my community told me todo it

#

and now it always accredits all amount of lines to everyone that contributed in the big squash/merge/base

#

i dont really know the words im learning how to use git

#

😭

#
git fetch -u origin dev 84977829beec6810504582fe53af5a555f70ad6c
git reset --hard 84977829beec6810504582fe53af5a555f70ad6c
git push -f -u origin test

if i do this then I have my full and exact history up until august 22

grizzled haloBOT
cunning egret
#

if those commits were done previously

fleet vortex
#

thats how far i came so far

cunning egret
#

if the commits you're talking about were squashed into one

#

you can still see them in git

fleet vortex
#

yeah the problem with the squashing is uh

#

if i add 3k lines

#

and another person in the squash added 1 line

#

we both get +3001 lines

#

as a contributor

#

i inflated everyones numbers this way

#

I owuld like to fix that

#

everyone got 3074 because they were included in the squash

#

is there any way to undo that squash?

cunning egret
#

yes

#

you can do anything u want with git

fleet vortex
#

yeah well! you just need to know how

#

thats where i fail

#

i managed to unsquash all up until aug 22, by just hard resetting to some point

#

but then i dont know how to pull in the rest

cunning egret
#

maybe this will help

fleet vortex
#

ohhhhhhhhhhh

#

wait maybe yes

#

i just point the thing somewhere else

#

so it skips that part?

#

i had that open earlier but it confused me more

#

so i just closed that tab

cunning egret
#

AFAIK you need git reflog

#

im not used to with this sorry

fleet vortex
#

yeah i can see the rebase in the history

#

ill see what i can do with this

#

in git reflog*

cunning egret
#

read more here

#

there is an example how to restore squashed commit(s)

fleet vortex
#

yeah thats basically what I did with my hard reset

#

the problem is that there have been commits happening after this

#

this example works fine

#

but then I still lose all the commits that happened after to where I reset to

#

like right now I am on the last commit of #42 before everything was squashed

#

actually nevermind, every pull request i merged was also squashed

#

#19 aswell

cunning egret
#

in that case you may need to add a keyword

#

git rebase -i -r HEAD~<commit_id>

fleet vortex
#

what exactly am i ment to edit in the rebase

#

everything is marked as pick

cunning egret
#

yeah pick means: the rebase will pick all those commits

#

you can change that pick with something else

#

you can see a list of options below

fleet vortex
#

yeah

#

but how does this help recover that history

cunning egret
#

you can see the commits you're looking for right ?

fleet vortex
#

yes

#

its the commit right before the dissapear

cunning egret
#

I dnt see anything would you like to show what you see rn ?

fleet vortex
#

im using vim

#

but thats the rebase window

#

i can move on to the next file

#

but i dont really understand whats happening

cunning egret
#

did you recover the squashed commits ?

fleet vortex
# fleet vortex

well they dont appear to be squashed from what i can see here

cunning egret
#

hmm

#

but how ? haha

#

tell me about one of them which one ?

fleet vortex
#

one moment

#

i see the entiry commit history except for merges / prs

#

if I add the -r you told me to the rebase i get an error

#

wait

#

oh wait

#

ok now i see it

#

or do i have to modify this on the main branch

#

when i open this in rebase

#

all i see is

#

need to leave for today, if anyone else has an idea how to recover all commits from the squashed merges within an active history please let me know

cunning egret
#

i think you need to add something in your rebase command

#

maybe this would help

#

git rebase -i --root -r HEAD~<commit_id>

#

im going to try it out

fleet vortex
#

cant do more for today, I will try this tomorrow morning and report back

#

thanks alot for the help so far ❤️

cunning egret
#

alright, keep me updated

#

im interested