9

I'm a bit confused about how to use IntelliJ's VCS options correctly.

We're working on a Git repo and I would like to understand how I can do the following in as few steps as possible:

  1. Stage and commit (prompt me for the "commit message")
  2. Pull/Push and Merge (automatically resolve conflicts that happened within the same class if the conflicts were not on the same line)

Indeed, if two different persons work on the same class, some times it is obvious that merges should be accepted if the two persons did not work on the same part of the class. Yet so far I've always had to specify the way I wanted the merge to happen in those cases.

I've read a bit about the "Update" option and I'm not sure I really understand what it does exactly. It does the Pull and Merge?

payne
  • 2,515
  • 2
  • 19
  • 46
  • 2
    It does: `stash` and then `pull --rebase` or `pull && merge` depending on the option you chose. – Stanislav Bashkyrtsev Jul 14 '18 at 21:02
  • `stash` and `rebase` are somewhat unknown to me as well. And does the `merge` do any automatic-resolving when one version of a class has a modification on line 2 and my version has a modification on line 234 so that I'm not prompted to confirm that the merge should indeed happen ? – payne Jul 14 '18 at 21:14

1 Answers1

15

You're asking 3 different questions, but I'm going to focus on the very last one (Update option).

First, I'd like to point out that the title (Git confusion (“Update” and “Pull”)) doesn't match with the answer you're looking for. Update is not a git command -- the update you're referring to is a feature offered by IntelliJ's git integration, which is a shortcut to an update strategy (merge or rebase).

Update Project

Options

Each option listed above correspond to an updating strategy:

Merge

Use merge update strategy

git fetch
git merge

or

git pull

Rebase

Use rebase update strategy

git fetch
git rebase

or

git pull --rebase

If you want to know the difference between merging and rebasing, I suggest you read this article: Merging vs. Rebasing.

Branch default

Use branch default update strategy

The above applies whatever update strategy you have set up in your .git/config configuration file for the specified branch.


As for Using Stash and Using Shelve, I've never used shelve myself, but it seems to be the same as git's stash except it's managed by IntelliJ instead of git.


NOTE: To specify, if you were fetching the master branch from your remote repository, you'd need to add origin master at the end of each commands above (e.g. git pull origin master, git pull --rebase origin master).


So to answer your question, Depending on the option you pick, Update either uses the merge update strategy (git pull or git fetch + git merge) or the rebase update strategy (git pull --rebase or git fetch + git rebase).

reference

TwiN
  • 2,887
  • 1
  • 16
  • 29
  • I might have forgotten to specify that I come from a "GitHub Desktop" background. I'm mostly used to pressing a few buttons. I've used the VCS from IntelliJ a few times to try it out, but it felt like I wasn't saving much time compared to GitHub Desktop. I really only want to know how I can make it so that the Merge *automatically* merges files when there is a conflict that is easy to fix. Now, based on what you are saying, using "Update" > "Merge" would do a "Pull", but without Pushing on the remote repo? How can I Commit+Push+Pull+Merge in one action ? – payne Jul 15 '18 at 06:08
  • @payne In git you **must** pull (and fix conflicts manually if needed) before you can push. So what you want is `commit`, `pull` (fix conflicts if necessary), then `push`. This can't be done in one action. – BigHeadCreations Jul 15 '18 at 11:01
  • The "fix conflicts manually" part, is there a way for me to set up Git so that if the conflict is in two different parts of the same class, it would just merge both parts together without requiring my intervention ? – payne Jul 15 '18 at 15:13
  • 1
    Git already works like this by default. Git doesn't know about classes or structures, it just works with lines of code. So as long as the changes to a class are on different lines of the file it will handle this automatically. You only get conflicts that you have to fix manually when there are changes to the same line and git doesn't know what to do. (Regarding conflicts, you may be interested in [merge strategy options](https://stackoverflow.com/questions/10697463/resolve-git-merge-conflicts-in-favor-of-their-changes-during-a-pull#10697551)) – BigHeadCreations Jul 16 '18 at 06:42