Git repo is having issues -


ok committed files after git add . --all apparently deleted files did rather saved them. there way recover these files? tried , ended screwing local repository well. not ever showing changes when push github.

m   .ds_store m   gemfile m   gemfile.lock d   app/assets/javascripts/hashtags.js.coffee d   app/assets/stylesheets/hashtags.css.scss m   app/assets/stylesheets/profiles.css.scss m   app/controllers/application_controller.rb d   app/controllers/hashtags_controller.rb d   app/controllers/moneytags_controller.rb m   app/controllers/postings_controller.rb d   app/controllers/usertags_controller.rb d   app/helpers/hashtags_helper.rb d   app/helpers/tags_helper.rb m   app/models/posting.rb d   app/views/hashtags/index.html.erb d   app/views/hashtags/show.html.erb m   app/views/layouts/application.html.haml d   app/views/moneytags/index.html.erb d   app/views/moneytags/show.html.erb m   app/views/postings/_form.html.erb d   app/views/postings/_posting.html.haml m   app/views/postings/index.html.erb m   app/views/postings/index.json.jbuilder m   app/views/postings/show.html.erb m   app/views/postings/show.json.jbuilder m   app/views/profiles/show.html.haml d   app/views/usertags/index.html.erb d   app/views/usertags/show.html.erb m   config/routes.rb m   db/migrate/20140301150615_create_postings.rb d   db/migrate/20140303200423_add_body_to_postings.rb d   db/migrate/20140305184935_create_supertag_tags.rb d   db/migrate/20140305184936_create_supertag_taggings.rb d   db/migrate/20140305214420_create_supertag_hashtags.rb d   db/migrate/20140305214421_create_supertag_hashtaggings.rb d   db/migrate/20140305214422_create_supertag_usertags.rb d   db/migrate/20140305214423_create_supertag_usertaggings.rb d   db/migrate/20140305214424_create_supertag_moneytags.rb d   db/migrate/20140305214425_create_supertag_moneytaggings.rb m   db/schema.rb d   test/controllers/hashtags_controller_test.rb d   test/helpers/hashtags_helper_test.rb 

the --all (or -a) flag git add means "auto-add new or changed files, , auto-remove files i've manually removed". or, more simply: "set next commit working-directory looks now."

the above indicates when ran git add . --all had, instance, app/assets/stylesheets/profiles.css.scss different head commit, had no file named app/assets/stylesheets/hashtags.css.scss. asked git please make next commit have different profiles.css.scss, not have hashtags.css.scss. did git commit new commit looks that.

is there way recover these files?

yes. they're in old commit. that's kind of point of commits: each commit has full , complete copy of work-tree.

it not ever showing changes when push github.

all push send new commit(s) receiving end, , update branch heads. in general, adds new commits (to remove commits during push must push --force or -f). so, each older version of file still available in older commits.

use git log or git log --all, or gitk --all or other graphical viewer, see old commits.

if want retrieve 1 file old commit, can use git show see it:

git show master~5:app/views/hashtags/index.html.erb 

will show file looked "five commits ago on branch master" (the ~5 gives number of commits "move in time", were).

to version of 1 file in working tree, , schedule old version going "next" commit, use git checkout:

git checkout master~5 -- app/views/hashtags/index.html.erb 

(the different syntax git show vs git checkout bit annoying, 1 can used it.)

if want undo "bad" commit, can use git revert:

git revert <bad-commit-id> 

this command says: "compare commit id gave you, commit comes before it. whatever changes made, make exact opposite change now." if deleted file, git creates old contents. if added text, git removes text. if deleted line file, git adds line file (in original place). if added file, git removes it.

you can revert any older commit, not recent, although in cases git may need assistance. instance, let's 3 commits ago (master~3) added 2 lines zorg.txt, , in last commit changed 1 of those. if attempt git revert master~3, git want delete both lines, 1 of them different now, won't sure do.

(reverting recent commit works, because there are—by definition—no newer changes interfering backing-out recent changes.)

in special cases, can discard last commit git reset --hard head^, there no going this, , if have pushed (published others) bad commit, have force-push result. meanwhile, may basing their work on bad commit; not expecting vanish, , you'll making work them recover. in general it's better revert published commit, rather discarding it. (revert adds new commit, cannot lose anything, add more stuff git borg collective, were.)

(to see how name commits, @ gitrevisions documentation. seems easiest use git log raw sha-1 names—things 676699a0e0cdfd97521f3524c763222f1c30a094—and cut-and-paste them mouse, if you're using command-line tools. it's learn names master^ , branch~4 , on.)


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -