1

First time ever working with git and command line for github and I think I messed up pretty bad. I was using an older version of this repository: https://github.com/nielsenramon/chalk. I downloaded, played around, made my own thing. Then I decided to upload to GitHub. What happened was I had no idea what I was doing, so in Git Bash, I typed in git init and then run/deploy. Problem is, in the readme file of the version I'm working on, it told me:

Important note: Chalk does not support the standard way of Jekyll hosting on GitHub Pages. You need to deploy your working branch (can be any branch, for xxx.github.io users: use another branch than master) with the bin/deploy script. Reason for this is because Chalk uses Jekyll plugins that aren't supported by GitHub pages. The bin/deploy script will automatically build the entire project, then push it to the gh-pages branch of your repo. The script creates that branch for you so no need to create it yourself.

You can find more info on how to use the gh-pages branch and a custom domain here.

View this for more info about automated deployment with Circle CI.

Here is what it has in bin/deploy:

#!/usr/bin/env sh

# Run this script to deploy the app to Github Pages.

# Exit if any subcommand fails.
set -e

echo "Started deploying"

# Checkout gh-pages branch.
if [ `git branch | grep gh-pages` ]
then
  git branch -D gh-pages
fi
git checkout -b gh-pages

# Build site.
yarn install --modules-folder ./_assets/yarn
bundle exec jekyll build

# Delete and move files.
find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \;
mv _site/* .
rm -R _site/

# Push to gh-pages.
git add -fA
git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]"
git push -f -q origin gh-pages

# Move back to previous branch.
git checkout -
yarn install --modules-folder ./_assets/yarn

echo "Deployed Successfully!"

exit 0

So when I ran run/deploy, I got this error message back: https://pastebin.com/MZPGvstX It also deleted a bunch of my files and I'm so confused as to what happened. I really hope I can at least recover it.

JakeD
  • 2,788
  • 2
  • 20
  • 29
therealnemis
  • 51
  • 1
  • 8
  • I think you need to add an [appropriate remote](https://git-scm.com/docs/git-remote#git-remote-emaddem)...what does `git remote -v` tell you that *origin* points to? – JakeD May 21 '18 at 01:24
  • I think that's where I messed up, I should've added a remote to my github repo – therealnemis May 21 '18 at 01:29
  • You didn't add a remote at all? I suggest you read this, although it doesn't sound like you actually broke anything: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ – JakeD May 21 '18 at 01:35
  • Yeah I really messed up, I should've added a remote. But a lot of the files I was working on is gone now, such as the layout folder, the css files, etc. I have no idea where they went – therealnemis May 21 '18 at 01:38
  • What branch were you working on? – JakeD May 21 '18 at 01:39
  • I typed the command in the master branch, but then it said it created a branch called gh-pages as one of the first things it did – therealnemis May 21 '18 at 01:41
  • From your pasteall link, everything looks fine to me until the *fatal: 'origin' does not appear to be a git repository*. This is not really a big deal at all, so the only way you actually lost something, as far as I can tell, is if the script literally deleted your working tree files before it makes the commit: *rm -R _site/*. Were your changes in that folder? Also, did you commit your changes to the master branch before running the script? – JakeD May 21 '18 at 01:45
  • no, I did not commit my changes to the master branch. I only created a repo (git init) and ran bin/deploy – therealnemis May 21 '18 at 01:49
  • Can you post the results of the following command: `git log --oneline --all --graph --decorate` – JakeD May 21 '18 at 01:56
  • the bin/deploy bash script is in my original post. It does remove _site folder, but that's just the compiled html anyways. Here's what your command returns: `* b62f593 (HEAD -> gh-pages) [ci skip]` – therealnemis May 21 '18 at 01:58
  • Yes, that's where I saw the `rm -R _site/`, but I don't know jekyll at all, so didn't know if you were using that. Can you post the results of the git log command I gave above, also, I just saw that at the end of the `find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \;` command, there is the `-exec rm -rf {}`. While I am by no means very knowledgeable about shell scripting, a cursory search suggests that it deletes the files that match the find criteria. Related to that element: https://unix.stackexchange.com/a/12904/220344 – JakeD May 21 '18 at 02:07
  • 1
    If that line does, indeed delete everything you did, at that point nothing would have been staged, stashed, or committed, so Git has nothing to do with it. – JakeD May 21 '18 at 02:09
  • Your command (git log --oneline --all --graph --decorate) returns for me `* b62f593 (HEAD -> gh-pages) [ci skip]` The files that the script seems to delete are all files that are unimportant anyways, as they are not supposed to be uploaded to github. Also, gh-pages seems to be the only branch left, I can't go back to the master branch – therealnemis May 21 '18 at 02:13
  • That doesn't make sense to me...at the beginning, `set -e` (bad practice: https://stackoverflow.com/a/19622569/6655092) is used, and then Git fails with the push, so the script should stop which it looks like it did. So between there, you have a new branch checked out, changes added, and changes committed. Nothing that I see to cause any harm to your repository. I hope to not come across as patronizing, but you can't do `git checkout master` and you don't have any other branches in the results of `git branch -a`? – JakeD May 21 '18 at 02:34
  • http://prntscr.com/jkgyxi I'm also really confused as to why even the master branch was deleted and why I can't go back to it – therealnemis May 21 '18 at 03:01
  • Are you sure that you had a master branch at all? If you never made a commit, I don't think it exists to branch off of, but I'm not at a computer to check. I don't think I'll be able to figure this out, but at least our comments are here for someone smarter than me to sift through. One more thing, what does git reflog say? – JakeD May 21 '18 at 03:18
  • http://prntscr.com/jkha6u - I think that's the master branch, see the parenthesis git reflog returns `b62f593 HEAD@{0}: commit (initial): [ci skip]` It's fine, dw about it. Thank you so much for all your help. Hopefully someone will be able to help haha – therealnemis May 21 '18 at 03:48
  • git reflog returns `b62f593 HEAD@{0}: commit (initial): [ci skip]` Also thank you so much for editing my original post. – therealnemis May 21 '18 at 04:28
  • Okay, so I opened it up in the GUI, then press create branch, but didn't create any new branches. In the command line, I typed in git branch -a and now there's a master – therealnemis May 21 '18 at 04:38
  • Figured it out. The delete everything section deletes everything **except** the sites folders and gitignore and everything else mentioned. Meaning it deleted my project. Goddamn – therealnemis May 21 '18 at 04:53

1 Answers1

0

It appears I don't have enough points to make a comment on this, but I believe my answer will fill out the missing gaps here.

I spoke with OP in a separate form of social media to get some clarity on the problem.

  1. There was the directory with project files in it
  2. The directory was not a git repository
  3. OP ran git init on that directory - but the working files were not staged nor committed
  4. The Chalk deploy script was then run after the init
  5. Script creates a branch
  6. Then it has a find command in it which looks for all files/dirs not .git, _sites, .gitignore - and then proceeds to run an rm -rf on everything it found
  7. The script then commits to that new gh-pages branch

OP showed me a screenshot of the "all branch history" window from Git GUI, and there is only one commit. The files were deleted before they were tracked, and as far as I know, are unrecoverable easily. If a revert were to be done, it would be bringing the directory to a point right after those files were rm'd

Jared
  • 18
  • 9
  • @JakeD - I spoke with OP separately and wanted to loop you in since you had commented earlier. – Jared May 21 '18 at 05:12
  • 1
    Yes, [that's what I thought](https://stackoverflow.com/questions/50440788/messed-up-pushing-to-github-now-would-like-to-revert-changes#comment87896587_50440788), but OP said such was not the case. Anyways, thanks for figuring it out...I thought I might be going mad. – JakeD May 21 '18 at 10:28