git(hub) lost all my changes in group project - eclipse

I am working on an eclipse project with two friends. We use Git(Hub) to work as efficient as possible. Here is the problem: I worked on the project and uploaded the changes. Unfortunately, my friends were not able to see my modifications. Nevertheless, I was still able to see my new version in eclipse. Now I tried to upload it again but "there was nothing to upload".
Then I used git fetch and rebase to see if something would happen.
Unfortunately, all changes are gone now. I used git commit --amend and they "found a swap file by the name xx with the date of my last upload!".
Does anyone know how can I get back to my working version now?

If you didn't push your changes after messed up local history, then reset your local with remote.
$ git branch <branch-name> # backup the branch for safety
$ git fetch # sync with remote
$ git reset --hard origin/<branch-name> # reset local branch with remote branch
Alternate: git reflog will show you the whole git history you executed the commands. Copy the last working commit-hash you want to go back.
$ git reflog
Checkout to that commit.
$ git checkout <commit-hash>
$ git log # see the commit history
If all things are ok. Then checkout to a new branch. If you do any change in new branch then do Add, Commit and Push or, just Push to remote.
$ git checkout -b new-branch # create a new branch called 'new-branch' and checkout to that branch
$ git add .
$ git commit -m 'message'
$ git push origin HEAD # push to remote new-branch

Related

Git Push "everything up to date" but file on github not change

after i learn to commit a file to github. now i have try to update file on github
by run syntax
git push -u origin main
and output message
Everything up-to-date
Branch 'main' set up to track remote branch 'main' from 'origin'.
when i check again on github the file that i was push no change at all
here my local file
please help me, im new to github
Have you committed first? With git, you need to commit your changes first, which is like saving each version locally. Then, when you push, you are publishing all of your versions to the remote (github).
Try the following:
git status
if it tells you about untracked files, use:
git add <filepath>
then:
git commit -m "<some commit message>"
This will save your changes as a commit locally, and you can now push this commit to github with the push command you used earlier.

Github Simple Commit Issue

I made modifications to my github repo on the actual website rather than the terminal. Now, I can't commit anything locally from my computer to my terminal because it says the files stored locally are not in sync with the github repo. How can I fix this so I can push my changes in terminal? Can I undo my previous commits that I did on the website?
(Optional) If you've some modifications locally, stash them first:
$ git stash
Because you've made some modifications at remote repo, you need to pull them down before pushing new commits (fix conflicts one by one if you got in this step):
$ git pull origin your_branch
Now your local branch & remote branch are in same stage, get back previously stashed modifications back (if you did step #1 before):
$ git stash pop
$ git add .
$ git commit -m "commit msg here"
It's OK to push local modifications to remote then:
$ git push origin your_branch
Btw, if you did modification at remote repo BY MISTAKE, and just want to use local repo as latest, you can push local repo to overwrite remote one (make sure remote repo's branch is not protected by server):
// !!! Use it wisely & carefully, cause it will overwrite the whole branch at remote side.
//
$ git push -f origin your_branch

How to delete GitHub blame history?

I'd like to delete the GitHub blame history that GitHub shows (tracking all changes made)
I am aware of how to how to roll back changes, but I am not trying to roll back any changes I have made, I am simply trying to delete this history of the changes.
Obviously, I do own the repository that I will be operating on (and am the sole owner)
If this is for all files of your GitHub repository, the simplest way would be to:
initialize a new local repository
add files from the original repo
add as remote the original repo GitHub URL
force push
That is:
git clone https://github.com/me/myrepo
git init myrepo2
cd repo2
git --work-tree=../myrepo add .
git checkout # -- .
git commit -m "Import myrepo"
git remote add origin https://github.com/me/myrepo
git push --force -u origin master

How to revert / undo my last two pushes (commit and revert) in github?

I got a Github repository from client where there is no code.
I cloned this repository and pasted my code folder to this repository and pushed the code to git.
But now I need to revert back my commit. For this I did the following steps:
git revert xxxxxxxxxxxxxxxx(commit)
git add .
git commit -a -m "reverted back"
git push origin master
After this I went to my github page, there I find project folder with app/views, config, db, log, public, tmp folders where revert is not properly done.
How to undo my last 2 commits (both commit and revert) and get back to the main repository as it is?
Please help me, I am worried.
The simplest way is just to hard reset to commit preceding the bad one:
git reset --hard xxxxxxxxxxxxxxxx^
git push -f origin <your-branch-name>
There xxxxxxxxxxxxxxxx is your sha, that you reverted in the first time.
Note the ^ before xxxxxxxxxxxxxxxx. It means that you reset to the commit before xxxxxxxxxxxxxxxx.
Or you can specify exact hash to reset to, i.e.
git reset --hard A
Before resetting your branch is looking like:
A -> xxxxxxxxxxxxxxxx -> B(bad)
After git reset --hard xxxxxxxxxxxxxxxx^
A
git push -f origin <your-branch-name> pushes your local changes made on the previous step to the Github server
Be careful with force pushing though, because you force your local repository state on the server. So you lose server state forever

How to push and clone yii2 projects to github?

I have developed a simple web-app with yii2 and pushed it to my github repository. I tried to clone it to another folder and test it, but it didn't work.
Something tells me that it is because I get my yii2 from an archive without composer and when I try to clone it, I use composer install command to get vendor folder and autoload file and it doesn't do it right.
Why is it happening and how can I push my web-apps properly to github so that everyone can clone and start them? Thanks in advance.
Once you've done the Yii2 app ready into you local, kindly follow below basic commands of Git.
Git Basic Commands
Git Checkout:
$ git clone CHECKOUT_URL
To check git files status:
$ git status
To add all file into git:
$ git add *
To add selected file into git:
$ git add filename1, filename2
To commit all added/updated/deleted files into Git:
$ git commit -m "initial commit" *
To commit selected file into git
$ git commit -m "initial commit" filename1, folder1
To push committed files into Git master branch:
$ git push -u origin master
To see all exists branches:
$ git branch
To create new branch:
$ git branch changes
To select branch:
$ git checkout changes
To commit into selected branch “changes”:
$ git push origin changes
Other Git Commands:
$ git --help
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG