Commit didn't work, but it did, but could not see it until sync. Why? - github

I'm learning about Github based off another training where the goal is to have training material synced via git between my Windows machine, where I edit them with VS Code, and a linux box where I do a git pull to get the changes and run the code.
The problem was that the first two test changes worked fine (edit the file in VS Code, stage, commit) and showed up in the repository. Doing a git pull from the linux box did update the local files.
Then it stopped. I worked on a few files, did a stage and commit and nothing happened. The VS Code console was not showing any errors, but the repository and the linux "git pull" commands did not show any changes. (this is commit 3)
I then added some more test changes and the same thing; stage, commit, no error, but the repository showed no difference, no update. (this is commit 4 and 5)
Then I did a stage and sync and there! Commits 3, 4, and 5 showed up in the repository!
So what happened? Does github have a time limit or commit amount limit I do not know? Or does sync do something special?
Why could I not see the commits 3, 4 or 5 before the sync? Am I doing something wrong?

There was a confusion in my understanding of how git and github are sructured.
Short answer: I was not pushing to the github repository.
Long answer: I had not understood the function of github and git and did not even think github and git were seperate.
As such, when I was staging, I thought that my changes are now ready. Then with a commit, I expected them to appear in my github repository, when in fact the commit was just adding them to the LOCAL depository.
I was commiting, but I was not pushing. And I was expecting my commits to show up in the github repository.

Related

Rebase master to upstream

I have a fork of microsoft/vscode-arduino on github. Some time ago I submitted a PR that was accepted. Time passed and now I want to do some more work.
At the time my use of git and github weren't very sophisticated and I rather foolishly did all the work on master.
On my local repo I pulled from upstream master, merged and committed to my fork, and was surprised to find that github thinks my fork is still 7 commits ahead and 113 behind.
Then I tried to rebase on the upstream as described on this page My pull request has been merged, what to do next? but the command
git pull --rebase origin master
and after a bit of mucking about I'm no commits behind and 12 commits ahead.
I really don't care about preserving anything. Everything important has long since been merged into the upstream repo. I just want to make this main exactly the same as current main in the upstream, so I can branch for my new efforts fixing an ongoing problem where every time there's a release of VS Code that uses a different version of node it breaks the serial port native integration until the Arduino extension is updated to the same release of Node and released.
Can anyone advise on how to do that? (discard the 12 commits ahead, not the N-API thing)
This may not be the most elegant but it worked.
Use GitLens in VS Code to find the oldest commit that isn't mine and do a hard reset to that.
In the terminal pane, git push --force. Refreshing the github page it now says I'm two commits behind origin (the repo I forked). I'm rid of the unwanted commits. Now to work forward.
In VS Code terminal pane git pull --rebase upstream master
In VS Code click on the status bar to sync.
Refresh the github web page. Hooray, This branch is even with microsoft:master.

How to see count of outgoing and incoming commits in git cli

While working with eclipse and git, I was able to see the counts of incoming and outgoing commits in the project explorer.
I am trying to see the same thing from git CLI but do not find any command for this over the internet and git documentation.
So can someone please help to get the answer how the git plugin in eclipse is doing this or there is any command which I may have missed.
This is not an exact answer, but if you just want a summary of the number of commits which have been made to the current branch, both locally and on the remote, then the base Git commands can do this:
git checkout your_branch
git fetch origin
git status
Just doing git status will say something like your branch and the remote have diverged by 3 and 5 commits, respectively. This means that since you synched, you have made 3 local commits, while other people have made 5 commits on the remote branch.
Obviously, these are just stats for one branch, but it seems along the lines of what you want.

What should I do when my local branch is at merging state after I pull the remote master?

I am an Android developer, and now I am doing a lot of changes locally and are trying to synchronize the local and github side of the code after I pull the merge to merge successfully and merge the code locally and run successfully.
But when I want to push always show the picture shown in the picture, push rejected. I am very puzzled, the left side of the figure is the local change, since I was a novice, no previous to ignore the file, so a series of build files, .idea files have been submitted to see the error is to show that these files are not merged.
Now I am very puzzled, how can I solve this situation, how can I submit the local code to my github library, who can help me? Many thanks!
Screenshot:
You have commits in the remote version of master that you're pushing to that are not in your local version, and vice versa. Since Git can't resolve this diversion automatically, you can't push your local version to your remote.
You may have to git pull, or if that doesn't work, git rebase, to get your branches to line up in a way that they can be merged.

How to recover replaced files in local Git repository after pull request?

Originally on my Github are some outdated styles.css and JavaScript files and others.
I was working on my project last night but didn't push it to Github or back it up. It was just saved in my local repository using a series of local, unpushed commits.
Being a newbie that I am, I did a git pull request master, and all the files in my local repository got replaced with the original styles.css and JavaScript that was in my github.
Is there a way to get those files back?
I did a git reset head#{2} where I believe the state of the repository before the pull request was, and it showed some unstaged files.
In Gitshell my command line has "master [+10 ~19 -42 !]" with the text master being yellow.
At this point, what do I do? Currently I seem to have lost a lot of work.
If you have performed commits often you can pretty much get to any of them.
Use git reflog first (https://git-scm.com/docs/git-reflog). It will show you all the interim commits you've made. Once you find a relevant one you can do git reset #commit_id.

EGit Commit to Remote Branch without Local Branch

I had a branch I was working on for a long time on my desktop. First I commit changes to my desktop's local branch, then push them to the remote branch and everything is dandy.
This morning, I was working on my laptop and selected the remote branch to change. The image below shows what my EGit repository window looked like on my laptop, except there was no local "MethodMigration" branch (there was a local master though). The remote "MethodMigration" branch had the little black check-mark next to it telling me that I'm viewing it as shown in the picture.
https://docs.google.com/file/d/0B7yGmb99B5enZm5OcTcydnEwLUE/edit (Sorry for the ghetto google drive link. I couldn't figure out how to get an image link)
Anyhow, I started adding a whole bunch of stuff. After I was done, I did a "Team->Commit->Commit & Push" after giving it a message. At that point, I remembered that I hadn't made a local branch for it yet... It told me "Nothing to push" even though a whole bunch of stuff had just been specified (which kind of makes sense since I never cloned the remote branch to make a local copy in the first place). The bad part is that all of my code was reverted back to the original "MethodMigration" remote branch code. Additionally, BitBucket shows no commits or anything.
Where did all my changed code go? Is there a way to get it back?
No worries!
You can use git reflog to find the commit id SHA of the lost commit. After that simply merge it with your local branch:
git merge <commit-id>