Git help... forgot to checkout branch after creating it.
Page 1 of 1
paxsali
Banned



Posts: 18352

PostPosted: Thu, 3rd Mar 2022 01:16    Post subject: Git help... forgot to checkout branch after creating it.
Guys, I fucked up ... badly.

I'm so stupid ... I created a new branch for a new feature "gwalk".

But I forgot to also check it out. So basically I'm in main, I create "gwalk", I don't check it out, I'm still in main and now I'm 5 commits in and just noticing it.

AHhhhhhhhh!!

How do I ...

A) merge what's in main back into the very first "gwalk" branch commit (5 commits ago)...
and
B) UNDO the changes in main as if they never happened.

My workdir is clean, meaning no pending changes, everything is commited.

Quote:
137518d (HEAD -> main) new baseline for gwalk branch
442c70f added .gitignore
857f45b major bugfix (using globstar, instead extglob), added gwalk()
850fef6 deleted unnecessary testcase.sh
1e6d724 added some testcases for find, os_walk, gwalk
33ec2ae (gwalk) snapshot before branching
618a05e cleanup. need to update project-template for main org file
f635e4d updated TODOs in org file
ad2b06d added some todos
6c883d3 working version 1.0
c84a8f8 snapshot
971ee4e updates to org file
1d44a28 new testing version (not working, yet)
8c1cdfe snapshot before making major changes...
ceb70ec deleted old obsolete funcs, added new org & project files
9a2d883 initial commit


I'm on latest commit 137518d right now but I noticed I should have been on gwalk since 33ec2ae but I'm not.

Please help potatxali.

Fenks.


"There will be no end to the troubles of humanity, until philosophers become kings, or kings become philosophers.", Plato.
"Hyperbole will destroy us all.", Matt Dillahunty.
"The hyperbole, the demonization of the other opinion and the unwillingness to even read the opposing opinion destroys the so important political discussions necessary for the well functioning of society.", Couleur
Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Thu, 3rd Mar 2022 01:22    Post subject:
Code:
git checkout gwalk
git merge main
git checkout main
git reset  --hard <last correct """mAiN""" commit hash>
git push --force
git checkout gwalk


My IMDb Ratings | Fix NFOHump Cookies | Hide Users / Threads | Embedded Content (Videos/GIFs/Twitter/Reddit) | The Derps Collection

Death smiles at us all; all we can do is smile back.


Last edited by LeoNatan on Thu, 3rd Mar 2022 01:25; edited 3 times in total
Back to top
AmpegV4




Posts: 6248

PostPosted: Thu, 3rd Mar 2022 01:23    Post subject:
Delete your existing branch "gwalk", create new branch "gwalk". Or you could checkout "gwalk" and merge the 5 commits from main into it. I'm presuming you want is the stuff in main in gwalk and main back 5 commits.

Then

Git reset --hard HEAD~5 on the main/master branch.
you need to force push this to remote if you pushed to remote.

git checkout gwalk

continue with day.
Back to top
paxsali
Banned



Posts: 18352

PostPosted: Thu, 3rd Mar 2022 01:35    Post subject:
⁢⁢


Last edited by paxsali on Thu, 4th Jul 2024 23:02; edited 2 times in total
Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Thu, 3rd Mar 2022 01:41    Post subject:
Ha, you took my other solution. With my edited commands you would have preserved the commits. But anyway, cheers.
Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Thu, 3rd Mar 2022 01:42    Post subject:
Back to top
AmpegV4




Posts: 6248

PostPosted: Thu, 3rd Mar 2022 05:44    Post subject:
Yep some CI platforms let you customize the way they clone the repo on execution, they almost always default to some broken way of doing it rather than just a "git clone repo". They also love to default shallow clone only 50 commits or so to save you downloading 1kb of data however you lose all your tags and commit history beyond those commits (Check its not doing that).

In the past when encountering issues with CI platform I resort to:

- Check CI config for anyway to change/customise the way it clones the repo on execution.
- CI never shallow clone ffs!
- Disable the CI from doing the initial clone and just script the git commands the way you want to get the job done.

I've looked at and avoided doing git submodules in the past as it would seem to add unnecessary complexity. Are there any advantages you get in nesting the repositories?, you have to run two commands anyway, if they weren't nested i presume this also wouldn't be a problem.

Lot of posts for this failure using submodules that may help:

https://stackoverflow.com/questions/56813479/cloning-a-repo-with-nested-submodules-does-not-work

https://stackoverflow.com/questions/64368977/git-fetch-fails-with-fatal-git-upload-pack-not-our-ref-a639-and-succeeds

 Spoiler:
 


Last edited by AmpegV4 on Thu, 3rd Mar 2022 06:11; edited 1 time in total
Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Thu, 3rd Mar 2022 06:04    Post subject:
The clone isn’t the problem. The problem is, there is a reference to a zombie commit somewhere. That is what needs to be found and fixed, not criticizing how Bitrise does their cloning. But thanks anyway.

The issue isn’t related in any way to shallow clone. The hash is discovered by a git fetch command.
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Applications
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group