This is what I want to do:
use Eclipse and Git (EGit)
use EGit to clone a remote repository to my local copy
make changes to my local copy
push those changes back to the remote repository
This is what I see:
after the push, the staged changes on the remote repository are the opposite to the changes I made.
Let me give an example and maybe someone can tell me where I have gone wrong.
I create a directory called C:\GIT\remote which contains a file called readme.txt which contains the string Hello World!
I turn this into a Git repository, I stage the readme.txt file, it shows:
new file mode 100644
## -0,0 +1 ##
+Hello World!
I commit this change at the remote repository. The remote repository contains no unstaged changes
Start Eclipse, import->Projects from Git->Clone URI. Location URI = C:\GIT\remote, Next, Next, Destination Directory: C:\GIT\local, Next, Import as General Project, Next, Finish
This creates a git repository in C:\GIT\local, with the readme.txt file and a .project file. As expected.
In Eclipse, I open the readme.txt file and edit it to say Goodbye World!. Save.
Right click on project in Project Explorer and: Team->Commit
Files to change are: readme.txt and .project. I enter a commit message "made changes" and click Commit.
Eclipse now shows that the local repository is 1 commit ahead of the remote repository. (Am I right?)
Right click on project in Project Explorer and: Team->Push to Upstream and it shows my comment and the remote repository details:
Now, when I look at the Staged files on my remote repository, I see this:
It's showing that the .project file needs to be removed (instead of being added), and that the change to the readme.txt file should be the reverse of the change I just made:
## -1 +1 ##
-Goodbye World!
+Hello World!
The C:\GIT\remote\readme.txt file contains the string "Hello World!". The staged patch doesn't even make sense according to the contents of the file.
I am puzzled.
No, those are the staged changes on remote. Not the commit history (the git log). Those are two different things.
The "Git GUI" is showing you the changes that you would need to commit directly to the remote repository to bring it into sync with the remote repository's working directory, which is still in the old state - out of date.
To avoid this confusion, developers often make the remote repository a bare repository - one with no working directory. Then it can only be pushed to and pulled from - not committed to directly.
Related
I created flutter new project in path /Users/hayat/flutter_development/flutter_project/flutter_application_1.
But VScode shows 10k changes in commit source control.
when I see those changes, it shows all changes in /Users/hayat/, which is upper folder than pwd.
I don't know why it happens and how to make it show only changes of flutter_application_1.
Your probably made a git init or at least have a .git folder in your /Users/hayat/ folder.
Best thing you can do is to delete the .git folder in /Users/hayat/, then you will be able to commit normal changes in your project folder. If VSCode don't detect any git repository, then, use the git init command to link your application folder to your remote git repository.
I want simply add a new File or Folder to an existing Repo in my Eclipse.
I tried the following (add index on the file and folder), but nothing happens.
Can someone help me.
In Git, a new file must first be added to the index (also called staging area) and then committed before the file becomes part of the history:
Add files:
Right-click and choose Team > Add to Index or
in the Git Staging view move the file from Unstaged Changes down to Staged Changes
Commit files: In the Git Staging view enter a Commit Message and click Commit
Result: In the History view a new commit containing the files is shown.
Please note in Git (in contrast to e.g. SVN) only files, but not empty folders can be committed.
Check the properties on that folder to get its path.
Switch to command line, and do a git status (if you have Git installed), to check if the folder and its content is actually in a Git repo (or if only "src" is):
Chec at least if you see a .git folder above the folder you want to add to the index, you should be able to do so from Eclipse.
But if not, that would explain why adding it does nothing.
Several months ago, I committed some code and files to the local Git Repository in Eclipse IDE. I did not push the changes to the central Git Repository. Later, I deleted those files and committed those changes again to the local Git Repository in Eclipse IDE. Now, I need those files again. So, I open the Git Reflog tab in Eclipse IDE. I scrolled down to the commit and double-click on it. This opens another tab showing me the message I wrote, the files and the branches. Here's a screenshot of the files.
If I double-click on a text file, an editor opens with the contents of the file. This is exactly what I need. However, if I double-click on the png file, an editor opens which shows me the textual representation of the bytes in the file. This isn't what I need. How do I get the actual file?
In another commit, the only files in the commit were images. So, I Cherry Picked them back into my branch.
It turns out one can checkout a commit, copy the files to temporary location, checkout the local branch, and then copy the files from the temporary location back into the branch.
This answer explains how do to the checkout.
I am new to git. I downloaded the desktop version (for Windows). I dragged the folder containing my project into the big window, "Get started by adding a repository." All the files showed up in the left window. Then I clicked on "Publish Repository". It then shows 143 files have changed, with 0 unsynced.
But when I go to my account on the git website, the repository is empty. The only files in it are .gitattributes and .gitignore. The whole idea here is that I want to share this project with other people.
Help out a git newbie and explain how I get the entire solution into git?
Thanks!
As you already have the remote repository at GitHub, you should use the clone option first to clone your repository locally.
This will create a folder (your repository clone) on the default location containing those two files.
Then you can copy your project files to this folder and try to sync again.
I have Eclipse Juno with EGit and a project that I've been working on for a while. I've decided to move it to Git, so I created a Github account and downloaded and installed the program. The repository is at C:\Users\username\GitHub\project_name\, but all it has is the README.md file.
How can I configure Eclipse to use my existing source code (in a workspace separate from the git folder) to work well with git? I've tried using Window → Show View → Other and selecting "Git Repositories," but other than adding a repository (which I have done) I can't figure out how to sync the code.
I've read this question but I get the impression that those answers will perform a one-time commit, instead of a sync.
To clarify: The repository does not have any code. I would like my existing code (in the Eclipse workspace) to be synced to the new repository.
If you already have a git repository in place, first copy all your files to that directory (yes, manually) and do a git commit -a to commit all the files into the repository. I'm assuming here that you've already initialized the repository at C:\Users\username\GitHub\project_name\ with git init.
In eclipse, go to File → Switch Workspace → Other... and point it to a workspace of your choice that can be completely different than the location of your code, or your earlier workspace. In fact, don't point it to the directory which contains your git repository.
Once you have a clean workspace, go to File → New → Other..., select Git → Git Repository and enter the path of your git repository (C:\Users\username\GitHub\project_name\). Enter a name for the repository, and click Finish.
I would really recommend you read at least the first few chapters of the git book to understand how git works, and to help you push and pull code to and from remote repositories.
If your existing repository is not git, you're going to have a hard time keeping the directories in sync. You might want to setup rsync to sync the directories. There is no way AFAIK for eclipse to automagically keep the two repositories in sync.