How to resolve conflict in GitLab using GitShell or GitHub Desktop - java

I am pretty new to GitLab because we just moved to it from ClearCase. I Cannot merge some changes into my remote then to my local repo because the GitHub Desktop says that there are some conflicts. I have been looking around to find a simple solution for this in order to view the conflicting file. I got quite a few changes in my local too so I don't want to play around too much with the unfamiliar Git commands because I don't want to loose any of my changes. Is there simple way to find out which file is causing the conflict. I used git status and it says that my local branch is up to date.
I am a little lost. Can someone give me some hints.
Thanks

If i understood correctly then
Is there simple way to find out which file is causing the conflict?
Then try this command git ls-files -u will give a list of conflicts from Git.
Also you want to save your local changes then use git stash if you don’t want to do a commit of half-done work and you can get back to this point later by using git stash apply

Related

How to update a Github project on IntellijIdea

Everyone
I don't know if the question has already been asked, but I'm looking everywhere but I can't find it.
I am working on a project on Intellij IDEA using GitHub.
I use my desktop computer at work to develop. After finishing I make a commit on Github and it is directly on my account.
But, sometimes I would like to continue at home on my laptop, using the same project as well as modifying and committing it.
Not knowing much about Github in integration with Intellij, I know that I can take an existing project and thus download it locally on my computer. But my question is, how can I update the changed files on each computer.
Example, I work at the office, I modified the A and B file, I commit it to Github, and at home on my computer, I update the Github project on Intellij and suddenly I have the new files modified.
If you have a solution, thank you!
I think you should need to take a "deeper" look into git fundamentals, here's a quick tutorial I think would do for your case:
Learn the Basics of Git in Under 10 Minutes
Also (if u can, and have the time) I would suggest you learn to use the git CLI before the IntelliJIDEA integrated plugin, so that, in case of problems, you know where to look under the hood.
To put it in easy words the most straight-forward thing you can do is (assuming you have already set-up a repo and a branch to work on):
(on the device you just worked on)
git commit -am "comment your wip here"
git push
(on the device where you want to get the work updated)
git pull

Can I overwrite a Git repo with a completely new project?

I got a new computer yesterday. I am coding in Android Studio for a course that I'm taking, and I figured it would be as easy as re-downloading Android Studio and cloning my repo onto the new computer. It isn't.
Something is messed up about my Gradle version, and I don't have the time to figure it out before the next due date.
The solution I've potentially come up with is, because my program is relatively small at the moment (only a couple files beyond the boiler-plate files that come with any Android activity), to just copy and paste the Java code from each of my files into a newly generated empty activity with all the right Gradle versions, and then just push that to the repository.
My question is: is that possible to do? If so, is it as easy as just pushing the new project (without having ever cloned the repository), or is it more complicated? If possible, elaboration on an answer would be greatly appreciated.
Thank you!
It's very straightforward to do it:
Clone the desired original project
Add your desired code on top of the clone
Add & commit your changed
Now you can push your changes in several ways:
You can have a new commit
git push origin <branch name>
You can overwrite the current commit on your remote
git push -f the -f will force to "overwrite" the existing code
Yes, you can.
You just have to link your new local project to the git repository,
once you push the new changes they will erase the old ones.

Git push not appearing in Github

I recently just made a few changes to my repository and committed and pushed everything as usual with no warnings or errors.
However, Github doesn't reflect these recent changes. When I look through the source files through Github's file view, all the files that I had changed look the same as before.
However, when I make a new clone of my repository and look through those files instead, they are all the most recent version with my committed updates.
How do I resolve this issue with github?
I had the same problem with a branch that I could not see on github it is actually due to the fact that github currently meets some issues as you can see here https://status.github.com/

Eclipse local changes for project

I can view local history of a single file with History View. But I need to see local changes for projects. I found that for remote changes. I need the same thing but for local changes.
if you are connected to a repository then it must be simple, please follow the following steps.
Right click on the project-->select team-->select show history.
This should do it.
If you don't have one then(pretty sure its not possible for entire project) you must consider getting one, i personally think github is useful

Is Git Smart Enough to Merge After Refactoring

Assume I have a class.
package org.my.domain;
public class BestClassEver{}
My Workflow
Through some refactoring, I change this class's package.
package org.another.domain;
public class BestClassEver{}
I commit this to my local repository using git and push it to a remote repository.
git add .
git commit -m "Refactoring"
git push origin master
Another Developer's Workflow
Another developer modifies the class, without pulling my changes.
package org.my.domain;
public class BestClassEver{
private String something;
}
Then commits and pushes to the remote repository
git add .
git commit -m "Some Changes"
git push origin master
Questions
Will Git merge the other developer's changes into the class?
If not, what happens?
Is this workflow something that needs to be coordinated amongst the team?
Git won't allow the other developer to push his changes without pulling.
It will throw an error that both refs don't match and therefore his local branch needs to be updated with the remote refs.
That's pretty much all there is to know about that. If there are changes in the remote repository, unless you do a forced push, git won't allow you to push changes if there are changes in the remote.
EDIT
Once he pulls, if there are any conflicts in the file, the developer will have to correct any conflicts, commit them and only then he will be able to push.
If there are no conflicts, git will automatically merge those changes and the developer will be able to push after the pull.
EDIT AGAIN
I didn't realize that you were moving the file. In any case, running git status would give you an idea as to the state of your local repository after a pull. If there was any conflicts, you'd be able to correct them.
NOTE
On git rebase or git pull --rebase are usually used to give you a much cleaner commit history as they will pretty much will apply any local changes on top of any other changes that were pulled.
On the other hand, git pull and git merge will usually make an extra commit to link the changes on the branches.
For more information take a look at this guide Git Rebasing
It is always good idea to let people work on different parts of program.
Merge or rebase in this case should be fully automatic, but in real world it is always a bit dramatic and sometimes there are some conflicts. Of course, this merge/rebase will be done after server rejects push for beeing non-fast-forward.
When such thing fails, some workarounds include:
Just repeating "refactoring" in the other branch prior to merging;
Converting the work to patch (git format-patch), editing the patch (applying that "refactor" to it) and applying the edited patch (git am). It is like manual rebasing.
I think it's better to separate merge-complicating refactoring (one that involves renaming, for example) and usual minor refactoing.
Sometimes for a merge-complicating refactoing a script can be written (such as find -name '*.c' -exec sed 's/something/anything/g' -i '{}' ';'). The script be used to repeat the refactoring multiple times in various places when we need it, so avoiding to merge refactored code with non-refactored one.
YES. Git is able to identify those changes. I am working on a project using git on my own fork (forked from origin). In the meantime another developer refactored the codebase on the original fork, which includes changing package structure.
I used the following commands:
git stash save // this saves all your work onto a personal stash
git pull // fetches all the latest changes on the primary fork and merges
git stash apply stash#{0} // or whatever the stash is where you saved your personal work
Now you will have the refactored codebase+your changes. You can now commit without any conflict and the packaging will not be changed.
Just note that in my case I waited for the original fork to be refactored and then I committed my changes, which are only changes to few files and not repackaging.
Also note that if you have added new files, then you might have to edit a few imports to make sure the imports are correct.
eg. import org.my.domain;
should now be edited to: import org.another.domain;

Categories