Error on creating new Git project in Visual Studio 2013 - c#

I'm using Visual Studio 2013 with the MS Git plugin. I'm trying to add an existing project to source control on my machine. The project is an empty project with one file. The path to the project solution is C:\_Projects\HelloGitWorld\HelloGitWorld.csproj - according to the git settings, I created the default repo location, but it doesn't seem to be storing the repo there (I tried this for other projects as well, and it created the repo in the same location as the solution).
So I basically right-clicked on the solution and chose 'add to source control'. This is simple enough, and as soon as I do that, I get:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I realize you can do this through git bash as well, and I will eventually move onto that, but right now I just want to add a local repo for this. Why won't it let me? Where is this trying to create a path that is too long?

Even though you create a project under your "default repo location" this does not mean a Git repo will be created for you. You need to create (or clone) a Git repository BEFORE creating a project/solution, or use the "Add to Source Control" option to ensure a new repo is created for you.
The "default repo location" is not a Git repo, and a solution folder is not (by default) a Git repo.
The real purpose of VS's "default git repo location" is so that VS tooling can locate any repositories you have cloned locally. It will search the immediate folder you specify and (I believe) any sub-folders. Any folders recognized as Git repository roots will then appear in the list of Repos in the 'connect' page of Visual Studio UI.
If you want to use the command-line this page on git-scm.com has a small snippet which shows how you could create a folder and initialize it as a git repo (locally.) Here is an example showing how to initialize your solution folder as a new, local Git repository from powershell (with msysgit installed):
set-alias git "C:\Program Files (x86)\Git\bin\git.exe"
cd "C:\_Projects\HelloGitWorld\"
git init
git add .
git status
From there you can launch visual studio, load your project/solution and see that git integration is now working as intended. The same set of commands can be executed from a CMD shell, but you will probably have to specify the full path to git, or just use git bash (which may be obtuse for you if you're not accustomed to using unix shells.)
If you don't want to use a command-line tool you can use Visual Studio Tools for Git and select "New.." from the "Connect to Team Projects" panel (thanks to Edward Thomson for pointing this out), or use a third party tool such as TortoiseGit. This will simplify the creation of a git repository without requiring you to understand how Git works, nor how to work with a command-line. For most simply scenarios you can rely entirely on Visual Studio Tools for Git. No need for anything third-party.
I use visualstudio.com and github.com for project hosting, as well as bare (private) repositories on a secure SAN at my home (since, in the end, you can't trust anyone anywhere with your private works. I don't care what people say.) You might find this article on saintsjd.com helpful in deciding if a bare repo is what you're really after, and this guide on stackoverflow to see how to create one yourself.
Let me know if I can clarify anything, or if you need some examples.

You've mentioned MS Git plugin - why you use it when VS2013 supports Git by default?
I'm using standard VS2013 Git integration + Git for Windows to sync my solution with Bitbucket and it works fine.
I also saw this strange default repo location setting, but all Git repos are actually placed inside .git folder under my solution when I use a solution context command "Add to source control..." (at this point you may create your Git repo from scratch). And actually .git folder + .gitattributes and .gitignore files are your local git repo which you may or may not sync with external hosted Git repo such as Bitbucket and Github. If you want to remove Git binding for you solution just remove mentioned folder and files.
As for the long path error you may check your actual solution path in Solution Explorer (select Solution root element and press F4).
Here are couple of links which may help you to get started:
Walkthrough for adding solution to Bitbucket repository (I followed it myself)
Visual Studio 2013 with Git (official)
It's worth mentioning here that if you're looking for a free hosted private Git repos then you might want to go on with Bitbucket (private repos are free for teams up to 5 people). If a small fee for private repos does not distract you then you might want to go on with Github which is the biggest Git repos hoster. Disclaimer: I'm not affiliated with Bitbucket and Github in any way, it's just a result of my personal investigation.
Also I must admit that I'm not a fan of command line tools so my solution is good if you don't like them also.

Related

Branch conflict in github when making changes to the same form in visual studio in 2 different branches [duplicate]

How do I resolve merge conflicts in my Git repository?
Try:
git mergetool
It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing by hand certainly.
As per Josh Glover's comment:
[This command]
doesn't necessarily open a GUI unless you install one. Running git mergetool for me resulted in vimdiff being used. You can install
one of the following tools to use it instead: meld, opendiff,
kdiff3, tkdiff, xxdiff, tortoisemerge, gvimdiff, diffuse,
ecmerge, p4merge, araxis, vimdiff, emerge.
Below is a sample procedure using vimdiff to resolve merge conflicts, based on this link.
Run the following commands in your terminal
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false
This will set vimdiff as the default merge tool.
Run the following command in your terminal
git mergetool
You will see a vimdiff display in the following format:
╔═══════╦══════╦════════╗
║ ║ ║ ║
║ LOCAL ║ BASE ║ REMOTE ║
║ ║ ║ ║
╠═══════╩══════╩════════╣
║ ║
║ MERGED ║
║ ║
╚═══════════════════════╝
These 4 views are
LOCAL: this is the file from the current branch
BASE: the common ancestor, how this file looked before both changes
REMOTE: the file you are merging into your branch
MERGED: the merge result; this is what gets saved in the merge commit and used in the future
You can navigate among these views using ctrl+w. You can directly reach the MERGED view using ctrl+w followed by j.
More information about vimdiff navigation is here and here.
You can edit the MERGED view like this:
If you want to get changes from REMOTE
:diffg RE
If you want to get changes from BASE
:diffg BA
If you want to get changes from LOCAL
:diffg LO
Save, Exit, Commit, and Clean up
:wqa save and exit from vi
git commit -m "message"
git clean Remove extra files (e.g. *.orig). Warning: It will remove all untracked files, if you won't pass any arguments.
Here's a probable use case, from the top:
You're going to pull some changes, but oops, you're not up to date:
git fetch origin
git pull origin master
From ssh://gitosis#example.com:22/projectname
* branch master -> FETCH_HEAD
Updating a030c3a..ee25213
error: Entry 'filename.c' not uptodate. Cannot merge.
So you get up-to-date and try again, but have a conflict:
git add filename.c
git commit -m "made some wild and crazy changes"
git pull origin master
From ssh://gitosis#example.com:22/projectname
* branch master -> FETCH_HEAD
Auto-merging filename.c
CONFLICT (content): Merge conflict in filename.c
Automatic merge failed; fix conflicts and then commit the result.
So you decide to take a look at the changes:
git mergetool
Oh my, oh my, upstream changed some things, but just to use my changes...no...their changes...
git checkout --ours filename.c
git checkout --theirs filename.c
git add filename.c
git commit -m "using theirs"
And then we try a final time
git pull origin master
From ssh://gitosis#example.com:22/projectname
* branch master -> FETCH_HEAD
Already up-to-date.
Ta-da!
I find merge tools rarely help me understand the conflict or the resolution. I'm usually more successful looking at the conflict markers in a text editor and using git log as a supplement.
Here are a few tips:
Tip One
The best thing I have found is to use the "diff3" merge conflict style:
git config merge.conflictstyle diff3
This produces conflict markers like this:
<<<<<<<
Changes made on the branch that is being merged into. In most cases,
this is the branch that I have currently checked out (i.e. HEAD).
|||||||
The common ancestor version.
=======
Changes made on the branch that is being merged in. This is often a
feature/topic branch.
>>>>>>>
The middle section is what the common ancestor looked like. This is useful because you can compare it to the top and bottom versions to get a better sense of what was changed on each branch, which gives you a better idea for what the purpose of each change was.
If the conflict is only a few lines, this generally makes the conflict very obvious. (Knowing how to fix a conflict is very different; you need to be aware of what other people are working on. If you're confused, it's probably best to just call that person into your room so they can see what you're looking at.)
If the conflict is longer, then I will cut and paste each of the three sections into three separate files, such as "mine", "common" and "theirs".
Then I can run the following commands to see the two diff hunks that caused the conflict:
diff common mine
diff common theirs
This is not the same as using a merge tool, since a merge tool will include all of the non-conflicting diff hunks too. I find that to be distracting.
Tip Two
Somebody already mentioned this, but understanding the intention behind each diff hunk is generally very helpful for understanding where a conflict came from and how to handle it.
git log --merge -p <name of file>
This shows all of the commits that touched that file in between the common ancestor and the two heads you are merging. (So it doesn't include commits that already exist in both branches before merging.) This helps you ignore diff hunks that clearly are not a factor in your current conflict.
Tip Three
Verify your changes with automated tools.
If you have automated tests, run those. If you have a lint, run that. If it's a buildable project, then build it before you commit, etc. In all cases, you need to do a bit of testing to make sure your changes didn't break anything. (Heck, even a merge without conflicts can break working code.)
Tip Four
Plan ahead; communicate with co-workers.
Planning ahead and being aware of what others are working on can help prevent merge conflicts and/or help resolve them earlier -- while the details are still fresh in mind.
For example, if you know that you and another person are both working on different refactoring that will both affect the same set of files, you should talk to each other ahead of time and get a better sense for what types of changes each of you is making. You might save considerable time and effort if you conduct your planned changes serially rather than in parallel.
For major refactorings that cut across a large swath of code, you should strongly consider working serially: everybody stops working on that area of the code while one person performs the complete refactoring.
If you can't work serially (due to time pressure, maybe), then communicating about expected merge conflicts at least helps you solve the problems sooner while the details are still fresh in mind. For example, if a co-worker is making a disruptive series of commits over the course of a one-week period, you may choose to merge/rebase on that co-workers branch once or twice each day during that week. That way, if you do find merge/rebase conflicts, you can solve them more quickly than if you wait a few weeks to merge everything together in one big lump.
Tip Five
If you're unsure of a merge, don't force it.
Merging can feel overwhelming, especially when there are a lot of conflicting files and the conflict markers cover hundreds of lines. Often times when estimating software projects we don't include enough time for overhead items like handling a gnarly merge, so it feels like a real drag to spend several hours dissecting each conflict.
In the long run, planning ahead and being aware of what others are working on are the best tools for anticipating merge conflicts and prepare yourself to resolve them correctly in less time.
Identify which files are in conflict (Git should tell you this).
Open each file and examine the diffs; Git demarcates them. Hopefully it will be obvious which version of each block to keep. You may need to discuss it with fellow developers who committed the code.
Once you've resolved the conflict in a file git add the_file.
Once you've resolved all conflicts, do git rebase --continue or whatever command
Git said to do when you completed.
Merge conflicts happens when changes are made to a file at the same time. Here is how to solve it.
git CLI
Here are simple steps what to do when you get into conflicted state:
Note the list of conflicted files with: git status (under Unmerged paths section).
Solve the conflicts separately for each file by one of the following approaches:
Use GUI to solve the conflicts: git mergetool (the easiest way).
To accept remote/other version, use: git checkout --theirs path/file. This will reject any local changes you did for that file.
To accept local/our version, use: git checkout --ours path/file
However you've to be careful, as remote changes that conflicts were done for some reason.
Related: What is the precise meaning of "ours" and "theirs" in git?
Edit the conflicted files manually and look for the code block between <<<<</>>>>> then choose the version either from above or below =====. See: How conflicts are presented.
Path and filename conflicts can be solved by git add/git rm.
Finally, review the files ready for commit using: git status.
If you still have any files under Unmerged paths, and you did solve the conflict manually, then let Git know that you solved it by: git add path/file.
If all conflicts were solved successfully, commit the changes by: git commit -a and push to remote as usual.
See also: Resolving a merge conflict from the command line at GitHub
For practical tutorial, check: Scenario 5 - Fixing Merge Conflicts by Katacoda.
DiffMerge
I've successfully used DiffMerge which can visually compare and merge files on Windows, macOS and Linux/Unix.
It graphically can show the changes between 3 files and it allows automatic merging (when safe to do so) and full control over editing the resulting file.
Image source: DiffMerge (Linux screenshot)
Simply download it and run in repo as:
git mergetool -t diffmerge .
macOS
On macOS you can install via:
brew install caskroom/cask/brew-cask
brew cask install diffmerge
And probably (if not provided) you need the following extra simple wrapper placed in your PATH (e.g. /usr/bin):
#!/bin/sh
DIFFMERGE_PATH=/Applications/DiffMerge.app
DIFFMERGE_EXE=${DIFFMERGE_PATH}/Contents/MacOS/DiffMerge
exec ${DIFFMERGE_EXE} --nosplash "$#"
Then you can use the following keyboard shortcuts:
⌘-Alt-Up/Down to jump to previous/next changes.
⌘-Alt-Left/Right to accept change from left or right
Alternatively you can use opendiff (part of Xcode Tools) which lets you merge two files or directories together to create a third file or directory.
Check out the answers in Stack Overflow question Aborting a merge in Git, especially Charles Bailey's answer which shows how to view the different versions of the file with problems, for example,
# Common base version of the file.
git show :1:some_file.cpp
# 'Ours' version of the file.
git show :2:some_file.cpp
# 'Theirs' version of the file.
git show :3:some_file.cpp
If you're making frequent small commits, then start by looking at the commit comments with git log --merge. Then git diff will show you the conflicts.
For conflicts that involve more than a few lines, it's easier to see what's going on in an external GUI tool. I like opendiff -- Git also supports vimdiff, gvimdiff, kdiff3, tkdiff, meld, xxdiff, emerge out of the box and you can install others: git config merge.tool "your.tool" will set your chosen tool and then git mergetool after a failed merge will show you the diffs in context.
Each time you edit a file to resolve a conflict, git add filename will update the index and your diff will no longer show it. When all the conflicts are handled and their files have been git add-ed, git commit will complete your merge.
I either want my or their version in full, or want to review individual changes and decide for each of them.
Fully accept my or theirs version:
Accept my version (local, ours):
git checkout --ours -- <filename>
git add <filename> # Marks conflict as resolved
git commit -m "merged bla bla" # An "empty" commit
Accept their version (remote, theirs):
git checkout --theirs -- <filename>
git add <filename>
git commit -m "merged bla bla"
If you want to do for all conflict files run:
git merge --strategy-option ours
or
git merge --strategy-option theirs
Review all changes and accept them individually
git mergetool
Review changes and accept either version for each of them.
git add <filename>
git commit -m "merged bla bla"
Default mergetool works in command line. How to use a command line mergetool should be a separate question.
You can also install visual tool for this, e.g. meld and run
git mergetool -t meld
It will open local version (ours), "base" or "merged" version (the current result of the merge) and remote version (theirs). Save the merged version when you are finished, run git mergetool -t meld again until you get "No files need merging", then go to Steps 3. and 4.
See How Conflicts Are Presented or, in Git, the git merge documentation to understand what merge conflict markers are.
Also, the How to Resolve Conflicts section explains how to resolve the conflicts:
After seeing a conflict, you can do two things:
Decide not to merge. The only clean-ups you need are to reset the index file to the HEAD commit to reverse 2. and to clean up working tree changes made by 2. and 3.; git merge --abort can be used for this.
Resolve the conflicts. Git will mark the conflicts in the working tree. Edit the files into shape and git add them to the index. Use git commit to seal the deal.
You can work through the conflict with a number of tools:
Use a mergetool. git mergetool to launch a graphical mergetool which will work you through the merge.
Look at the diffs. git diff will show a three-way diff, highlighting changes from both the HEAD and MERGE_HEAD versions.
Look at the diffs from each branch. git log --merge -p <path> will show diffs first for the HEAD version and then the MERGE_HEAD version.
Look at the originals. git show :1:filename shows the common ancestor, git show :2:filename shows the HEAD version, and git show :3:filename shows the MERGE_HEAD version.
You can also read about merge conflict markers and how to resolve them in the Pro Git book section Basic Merge Conflicts.
For Emacs users which want to resolve merge conflicts semi-manually:
git diff --name-status --diff-filter=U
shows all files which require conflict resolution.
Open each of those files one by one, or all at once by:
emacs $(git diff --name-only --diff-filter=U)
When visiting a buffer requiring edits in Emacs, type
ALT+x vc-resolve-conflicts
This will open three buffers (mine, theirs, and the output buffer). Navigate by pressing 'n' (next region), 'p' (prevision region). Press 'a' and 'b' to copy mine or theirs region to the output buffer, respectively. And/or edit the output buffer directly.
When finished: Press 'q'. Emacs asks you if you want to save this buffer: yes.
After finishing a buffer mark it as resolved by running from the teriminal:
git add FILENAME
When finished with all buffers type
git commit
to finish the merge.
Bonus:
In speaking of pull/fetch/merge in the previous answers, I would like to share an interesting and productive trick,
git pull --rebase
This above command is the most useful command in my Git life which saved a lot of time.
Before pushing your newly committed change to remote server, try git pull --rebase rather git pull and manual merge and it will automatically sync the latest remote server changes (with a fetch + merge) and will put your local latest commit at the top in the Git log. No need to worry about manual pull/merge.
In case of a conflict, just use
git mergetool
git add conflict_file
git rebase --continue
Find details at: What does “git pull –rebase” do?
Simply, if you know well that changes in one of the repositories is not important, and want to resolve all changes in favor of the other one, use:
git checkout . --ours
to resolve changes in the favor of your repository, or
git checkout . --theirs
to resolve changes in favor of the other or the main repository.
Or else you will have to use a GUI merge tool to step through files one by one, say the merge tool is p4merge, or write any one's name you've already installed
git mergetool -t p4merge
and after finishing a file, you will have to save and close, so the next one will open.
There are three steps:
Find which files cause conflicts by the command
git status
Check the files, in which you would find the conflicts marked like
<<<<<<<<head
blablabla
Change it to the way you want it, and then commit with the commands
git add solved_conflicts_files
git commit -m 'merge msg'
Please follow the following steps to fix merge conflicts in Git:
Check the Git status:
git status
Get the patchset:
git fetch (checkout the right patch from your Git commit)
Checkout a local branch (temp1 in my example here):
git checkout -b temp1
Pull the recent contents from master:
git pull --rebase origin master
Start the mergetool and check the conflicts and fix them...and check the changes in the remote branch with your current branch:
git mergetool
Check the status again:
git status
Delete the unwanted files locally created by mergetool, usually mergetool creates extra file with *.orig extension. Please delete that file as that is just the duplicate and fix changes locally and add the correct version of your files.
git add #your_changed_correct_files
Check the status again:
git status
Commit the changes to the same commit id (this avoids a new separate patch set):
git commit --amend
Push to the master branch:
git push (to your Git repository)
CoolAJ86's answer sums up pretty much everything. In case you have changes in both branches in the same piece of code you will have to do a manual merge. Open the file in conflict in any text editor and you should see following structure.
(Code not in Conflict)
>>>>>>>>>>>
(first alternative for conflict starts here)
Multiple code lines here
===========
(second alternative for conflict starts here)
Multiple code lines here too
<<<<<<<<<<<
(Code not in conflict here)
Choose one of the alternatives or a combination of both in a way that you want new code to be, while removing equal signs and angle brackets.
git commit -a -m "commit message"
git push origin master
You could fix merge conflicts in a number of ways as other have detailed.
I think the real key is knowing how changes flow with local and remote repositories. The key to this is understanding tracking branches. I have found that I think of the tracking branch as the 'missing piece in the middle' between me my local, actual files directory and the remote defined as origin.
I've personally got into the habit of 2 things to help avoid this.
Instead of:
git add .
git commit -m"some msg"
Which has two drawbacks -
a) All new/changed files get added and that might include some unwanted changes.
b) You don't get to review the file list first.
So instead I do:
git add file,file2,file3...
git commit # Then type the files in the editor and save-quit.
This way you are more deliberate about which files get added and you also get to review the list and think a bit more while using the editor for the message. I find it also improves my commit messages when I use a full screen editor rather than the -m option.
[Update - as time has passed I've switched more to:
git status # Make sure I know whats going on
git add .
git commit # Then use the editor
]
Also (and more relevant to your situation), I try to avoid:
git pull
or
git pull origin master.
because pull implies a merge and if you have changes locally that you didn't want merged you can easily end up with merged code and/or merge conflicts for code that shouldn't have been merged.
Instead I try to do
git checkout master
git fetch
git rebase --hard origin/master # or whatever branch I want.
You may also find this helpful:
git branch, fork, fetch, merge, rebase and clone, what are the differences?
If you want to merge from branch test to master, you can follow these steps:
Step 1: Go to the branch
git checkout test
Step 2:
git pull --rebase origin master
Step 3: If there are some conflicts, go to these files to modify it.
Step 4: Add these changes
git add #your_changes_files
Step 5:
git rebase --continue
Step 6: If there is still conflict, go back to step 3 again. If there is no conflict, do following:
git push origin +test
Step 7: And then there is no conflict between test and master. You can use merge directly.
Using patience
For a big merge conflict, using patience provided good results for me. It will try to match blocks rather than individual lines.
If you change the indentation of your program for instance, the default Git merge strategy sometimes matches single braces { which belongs to different functions. This is avoided with patience:
git merge -s recursive -X patience other-branch
From the documentation:
With this option, merge-recursive spends a little extra time to avoid
mismerges that sometimes occur due to unimportant matching lines
(e.g., braces from distinct functions). Use this when the branches to
be merged have diverged wildly.
Comparison with the common ancestor
If you have a merge conflict and want to see what others had in mind when modifying their branch, it's sometimes easier to compare their branch directly with the common ancestor (instead of our branch). For that you can use merge-base:
git diff $(git merge-base <our-branch> <their-branch>) <their-branch>
Usually, you only want to see the changes for a particular file:
git diff $(git merge-base <our-branch> <their-branch>) <their-branch> <file>
git log --merge -p [[--] path]
Does not seem to always work for me and usually ends up displaying every commit that was different between the two branches, this happens even when using -- to separate the path from the command.
What I do to work around this issue is open up two command lines and in one run
git log ..$MERGED_IN_BRANCH --pretty=full -p [path]
and in the other
git log $MERGED_IN_BRANCH.. --pretty=full -p [path]
Replacing $MERGED_IN_BRANCH with the branch I merged in and [path] with the file that is conflicting. This command will log all the commits, in patch form, between (..) two commits. If you leave one side empty like in the commands above git will automatically use HEAD (the branch you are merging into in this case).
This will allow you to see what commits went into the file in the two branches after they diverged. It usually makes it much easier to solve conflicts.
As of December 12th 2016, you can merge branches and resolve conflicts on github.com
Thus, if you don't want to use the command-line or any 3rd party tools that are offered here from older answers, go with GitHub's native tool.
This blog post explains in detail, but the basics are that upon 'merging' two branches via the UI, you will now see a 'resolve conflicts' option that will take you to an editor allowing you to deal with these merge conflicts.
Merge conflicts could occur in different situations:
When running git fetch and then git merge
When running git fetch and then git rebase
When running git pull (which is actually equal to one of the above-mentioned conditions)
When running git stash pop
When you're applying git patches (commits that are exported to files to be transferred, for example, by email)
You need to install a merge tool which is compatible with Git to resolve the conflicts. I personally use KDiff3, and I've found it nice and handy. You can download its Windows version here:
https://sourceforge.net/projects/kdiff3/files/
BTW, if you install Git Extensions there is an option in its setup wizard to install Kdiff3.
Then setup the Git configuration to use KDiff3 as its mergetool:
$ git config --global --add merge.tool kdiff3
$ git config --global --add mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
$ git config --global --add mergetool.kdiff3.trustExitCode false
$ git config --global --add diff.guitool kdiff3
$ git config --global --add difftool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
$ git config --global --add difftool.kdiff3.trustExitCode false
(Remember to replace the path with the actual path of the KDiff3 EXE file.)
Then every time you come across a merge conflict, you just need to run this command:
$ git mergetool
Then it opens Kdiff3, and first tries to resolve the merge conflicts automatically. Most of the conflicts would be resolved spontaneously and you need to fix the rest manually.
Here's what Kdiff3 looks like:
Then once you're done, save the file and it goes to the next file with a conflict and you do the same thing again until all the conflicts are resolved.
To check if everything is merged successfully, just run the mergetool command again. You should get this result:
$ git mergetool
No files need merging
I always follow the below steps to avoid conflicts.
git checkout master (Come to the master branch)
git pull (Update your master to get the latest code)
git checkout -b mybranch (Check out a new a branch and start working on that branch so that your master always remains top of trunk.)
git add . and git commit and git push (on your local branch after your changes)
git checkout master (Come back to your master)
Now you can do the same and maintain as many local branches you want and work simultaneous by just doing a git checkout to your branch whenever necessary.
I understood what a merge conflict was, but when I saw the output of git diff, it looked like nonsense to me at first:
git diff
++<<<<<<< HEAD
+ display full last name boolean in star table
++=======
+ users viewer.id/star.id, and conversation uses user.id
+
++>>>>>>> feat/rspec-tests-for-cancancan
But here is what helped me:
Everything between <<<<<<< and ======= is what was in one file, and
Everything between ======= and >>>>>>> is what was in the other file
So literally all you have to do is open the file with the merge conflicts and remove those lines from either branch (or just make them the same), and the merge will immediately succeed. Problem solved!
GitLens for Visual Studio Code
You can try GitLens for Visual Studio Code. The key features are:
3. Easily resolve conflicts
I already like this feature:
2. Current Line Blame.
3. Gutter Blame
4. Status Bar Blame
And there are many features. You can check them here.
This answer is to add an alternative for those Vim users like me that prefers to do everything within the editor.
TL;DR
Tpope came up with this great plugin for Vim called fugitive. Once installed, you can run :Gstatus to check the files that have conflict and :Gdiff to open Git in a three-way merge.
Once in the three-way merge, fugitive will let you get the changes of any of the branches you are merging in the following fashion:
:diffget //2, get changes from original (HEAD) branch:
:diffget //3, get changes from merging branch:
Once you are finished merging the file, type :Gwrite in the merged buffer.
Vimcasts released a great video explaining these steps in detail.
I am using Microsoft's Visual Studio Code for resolving conflicts. It's very simple to use. I keep my project open in the workspace. It detects and highlights conflicts. Moreover, it gives GUI options to select whatever change I want to keep from HEAD or incoming.
git fetch <br>
git checkout **your branch**<br>
git rebase master<br>
In this step you will try to fix the conflict using your preferred IDE.
You can follow this link to check how to fix the conflict in the file.
git add<br>
git rebase --continue<br>
git commit --amend<br>
git push origin HEAD:refs/drafts/master (push like a drafts)<br>
Now everything is fine and you will find your commit in Gerrit.
Try Visual Studio Code for editing if you aren't already.
After you try merging (and land up in merge conflicts), Visual Studio Code automatically detects the merge conflicts.
It can help you very well by showing the changes made to the original one and if you should accept incoming or
current change (meaning original one before merging)'.
It helped me and it can work for you too!
PS: It will work only if you've configured Git with with your code and Visual Studio Code.
A safer way to resolve conflicts is to use git-mediate (the common solutions suggested here are quite error prone imho).
See this post for a quick intro on how to use it.
For those who are using Visual Studio (Visual Studio 2015 in my case)
Close your project in Visual Studio. Especially in big projects, Visual Studio tends to freak out when merging using the UI.
Do the merge in a command prompt.
git checkout target_branch
git merge source_branch
Then open the project in Visual Studio and go to Team Explorer → Branch. Now there is a message that says Merge is pending and conflicting files are listed right below the message.
Click the conflicting file and you will have the option to Merge, Compare, Take Source, and Take Target. The merge tool in Visual Studio is very easy to use.

Deploying and running bot framework v4.4+ from template works but deploying and running using fork and source control doesn't work

Summary
I am trying to deploy the latest Microsoft Virtual Assistant code. In the documentation, they describe a process to deploy and run the bot using a Visual Studio template. The whole process described in the documentation works great.
However, I don't like using a template. I don't want to loose Microsoft's Git history. Also, this deployment needs to stand the tests of time, and I want to make it as simple as possible to merge updates from Microsoft.
Inside of Microsoft's repo, there is a subdirectory containing the C# Virtual Assistant template and a sample of the code as if it were deployed by the template.
Means of preserving Git history, ability to pull new commits, etc.
I'll describe my solution, which lets me preserve Microsoft's Git history, pull their latest commits with ease and still gives me a reasonably sized project for working on my client's bot deployment (the Microsoft AI repo is huge and contains many things I don't want in my bot deployment). The resulting branch/project that I'm working on very closely resembles (vide infra, appears identical to) the solution/project that I get when I create it from the template in Visual Studio.
I forked Microsoft's entire GitHub repo.
I setup a local Git repository with both Microsoft's repository and my fork as remotes.
I used Git subtree, as described on this Stack Overflow post to filter the repo down to just the Virtual Assistant C# sample code. I created a branch for this subtree.
I copied the subtree branch into a develop branch, where I intend to do all my custom development.
I can use master on Microsoft's upstream remote and the newly created subtree branch to continually pull new commits from Microsoft into my personal develop branch.
Here's some pseudo-code that roughly walks through the process.
$ git checkout upstream/master
Switched to branch upstream/master
Your branch is up to date with 'r_microsoft/master'.
$ git subtree split --prefix=templates/Virtual-Assistant-Template/csharp/sample --onto upstream/virtual-assistant-csharp -b upstream/virtual-assistant-csharp
$ git checkout upstream/virtual-assistant-csharp
$ git checkout -b eric/develop
Switched to branch 'eric/develop'
Your branch is up to date with 'r_eric/develop'.
$ git rebase upstream/virtual-assistant-csharp
Current branch eric/develop is up to date.
Deploying and running the bot
Using this subtree instead of the solution that is created from the template, I followed the directions for deployment and running the bot. Microsoft has a separate Markdown page for the deployment (linked just in case you want to check it out).
The deployment appears to run successfully. I replaced sensitive info with xxx.
PS C:\Users\eric\bot\VirtualAssistantSample> .\Deployment\Scripts\deploy.ps1 -name "personal-bot-test-using-git" -location "westus" -luisAuthoringKey "xxx" -luisAuthoringRegion "westus" -resourceGroup "personal-bot-test-using-git" -appId "xxx" -appPassword "xxx"
> Creating resource group ...
> Deploying Azure services (this could take a while)...
> Updating appsettings.json ...
> Deploying cognitive models ...
> Initializing dispatch model ...
> Parsing general LU file ...
> Deploying general LUIS app ...
> Adding general app to dispatch model ...
> Parsing chitchat LU file ...
> Deploying chitchat QnA kb ...
> Adding chitchat kb to dispatch model ...
> Parsing faq LU file ...
> Deploying faq QnA kb ...
> Adding faq kb to dispatch model ...
> Creating dispatch model...
> Done.
I did everything exactly according to their steps (besides not using the template). When I build, no errors. Running the bot shows no errors.
Here's me connecting using Microsoft's Bot Emulator (replaced sensitive values).
However, when I test the bot, no dice. It doesn't display the welcome message.
And communication doesn't work.
.
Here's what the POST 400 directline.postActivity says.
{
"error": {
"code": "ServiceError",
"message": "Refresh access token failed with status code: 401"
}
}
On the other hand, if I do all the same steps, except start from the project/solution created by the template, it just works.
.
Additional Context
I tried the whole process using both Visual Studio 2019 and 2017 with the latest NuGet packages. There doesn't seem to be any differences.
With my means of getting the project started, there's no .sln file. So I open up the project using the .csproj file. Using the bot template, it creates a .sln file that I can use to open up the whole thing. Regardless of whether I open up the project that was deployed from the template using .sln or the .csproj, it works.
I compared the bot's directories (subtree from source code vs created by template) using WinMerge. There are no significant differences that I can see (of course I can't dig through the contents of .dll files).
EDIT ~ 8 hours after creating. It appears that bots created even with the template are no longer functioning?
#EricHansen and I conversed about this in his related GitHub Issue. Since the information may be valuable to others, I'll include the "answer" here:
401s are almost always caused by mismatched MicrosoftAppId/MicrosoftAppPassword. Ensure that they match in all of these locations:
appsettings.json/.env/.bot, whatever is applicable
The App Registration
The one you use when opening Emulator
If that doesn't work, follow the Authentication Troubleshooting Guide
You should also ensure all of your packages are up to date, including:
NuGet/npm packages
The ones from the BotBuilder-Tools Repo
Emulator
OPs resolution was most likely related to this:
I've definitely had issues with some password strings. The
README notes that it has trouble with passwords containing #. I know I've
had trouble with another password, however (I don't remember what
special character gave it the issue). I would guess that this was the
issue.
My best guess is that it was either an issue with a special character
in a password, emulator caching id/pass in some unexpected way, or IIS
Express caching id/pass in some way. Usually, if I'm switching bots
with the same endpoints and running into trouble, I restart those and
it usually works.

How do I build code out of a tutorial repo that has many examples (in Visual Studio/C#)

How do I build sample code, split into folders in a repo, from a class or tutorial, in Visual Studio?
So - I'm pretty much a noob at C#, I've gone through a lot of tutorials and browsed through some large C# projects from work and built them, and done some other minor things. I'm going through a course on writing testable code on Pluralsight. He has a public Github repo for the code examples, writing-testable-code. I connected to the repo and downloaded it okay into a local Git repo. I was able to download all the packages from NuGet and they are all showing as the version he used (a few have updates, but I figured updating might break things).
I can't figure out how to run this code, build it, or run the tests in it.
What I tried so far
My issue is - I open the solution, and there are a bunch of files and folders - each module/chapter is split into folders (i.e. Module1/Easy, Module1/Hard, Module2/Easy, etc.). I want to build the Module1/Easy folder, including unit test examples, and run the tests.
When reviewing Module1/Easy, it has 3 files that should build okay - the program.cs has a main() and looks like a console app, the Calculator.cs has a simple class, and the CalculatorTests.cs has unit tests built for Nunit. The solution has NUnit, Castle.core, and things from later modules (Moq, AutoMoq, Unity, Ninject, etc.). It didn't seem to have a VS runner, so I added Nunit3TestAdapter - the guy in the course has resharper installed, which I don't, and he was using the Resharper test runner, which would explain why he didn't include it.
I tried setting the "Module1/Easy/Project.cs" file the "Set as Startup Item", since it has a main and looks setup as a console app. However, running it (the "Start" button turned into a "Program.cs" button), it fails saying it can't run a dll. The tests aren't showing up in the Test Explorer like some other small projects I've built from examples.
What's the right way to do this?
I'm not sure where to go from here. On the Build menu is only a "Build Solution" and one about Code Analysis - I'm used to a lot more options here. It feels like I have to turn this folder into a project, maybe? I can always reinstall the packages - but what is the best solution here?
I've run into this before on other book, tutorial, or class repos, but finally decided to figure out how to get this one working. I appreciate any help!
Notes
I'm running Visual Studio Community 2017 at the moment.
I can post some of the files, but the repo is publically available, and not sure exactly what to post to help.
Progress from comments and answers
Per Biker-Dude's answer, I switched the project to build a console app rather than a dll, and now I get a compile-time error for having multiple entry points (i.e. every module and sub folder has its own Main() function and should probably be a separate project).
After #1, I removed all folders but one from the solution, it will then compile, run the tests, etc. - but I eventually want to be able to at least separately compile every sub-folder - what's the best way?
The problem must be that the project must have the output type set to class libraries. Browse through the solution tree and:
Select your class's project> right click > Properties > Application >
Output Type > Console Application/ Windows Application.
This should fix it, if the other things are set up properly.
With the help of BikerDude's answer and stijn's comments, I was eventually able to play around with this and get some things working.
First of all, don't try to exclude any folders in this situation, that will just make things worse! They will still be in your underlying folder/repo, just won't be showing up in your solution anywhere, and you won't be able to create a new folder with the same name (weird decision...). And you'll have to add them back in as individual files - I think.
The best solution (so far)
The best solution seems to be:
Create a new project for each buildable set of files in the solution (in my case, at least one project per "module" folder). I used the ".Net framework console app" project type (right click on the solution, use Add/New Project) to get things to work, but this would depend on the particular course or tutorial repo you downloaded.
Move the folder or sub-folder that has the files you want to build out of the main solution and into the new project - you can click and drag to move it.
Visual Studio will make an empty, pre-formatted file in your project that you likely have to delete - for .Net apps, this is the "Program.cs" file in C#. For one of my folders this file already existed, and I had to delete the new one in order to build. Another folder from a different module was setup more like a library and couldn't build standalone, but this procedure did get me to being able to build the files and that allowed the unit tests to show up in the test explorer and run the tests successfully (which was the main point of that module).
Go to the solution and right-click and choose "Manage Nuget Packages for Solution". As long as all the packages are installed for the main solution, then they will all show up in the list of Installed Packages (you might need to click on the "Installed" tab). You can click on each package in turn, then on the right you can checkmark the new project, and the "Install" button should be available - click it. Repeat for all the packages to install them all. Note that you can cut out some repetition here if you create all the projects you need first, then you can install all of them at the same time in this step (i.e. checkmark all the new projects at once instead of reopening the package manager each time).
You might have to fix the NameSpace - it should be consistent within the files/folders you transferred from the original solution, but if you add any new files to play with things, the Namespace for it will likely not match, and to see classes, etc. in the original files, you'll have to update your Namespace on the new files.
Per BikerDude's answer - After transferring everything to new projects, if you keep anything in the original project that came with the solution, it might not be trying to build the right type of item. You may be able to fix that by right-clicking the project, selecting properties, and adjusting the "output type", but it may not have the options you need. If it doesn't, just create a new project with the right type and transfer the files as above.
After following the above steps, I was able to build each new project I created, using the original files from folders that I moved. Mainly I just needed to build, which enabled all the unit tests that this tutorial/class was focused on, but this allowed me to build the console apps as well, when present.
Thanks for the help from all in pointing me in the right direction!

Git with Visual Studio 2015 not allowing my partner to create a new project

Git, used with VS 2015, as the title indicates, is having issues; we're creating a large application that so far has 16 projects for separation of concerns.
The majority of the time, git is fine, although sometimes it does untrack things we don't want it to. Probably, it's just because we're so busy doing things, we don't realize sometimes that new files aren't always tracked by Git by default. Whatever.
But now, my partner has created a new project for our API services, and it untracks the project and class files; but when he adds them back into the commit and commits the entire thing, it will either not let him commit, or it will say it's committed, and then I cannot get it from syncing with him. It's like Git just doesn't want the project to exist.
I can upload projects just fine. I uploaded a new project and added references to a couple of our other projects, and committed, and everything worked fine when he sync'd up. But for some reason, he can't create this one project. We're not sure why.
And, we can't seem to access the command prompt on his machine because he has a separate drive for his data, he stores everything on his D: drive. Command prompt will not access his D: drive for some reason. We can probably look up that issue and figure it out quickly, if we need to use command prompt with Git to fix this issue. But we're simply wondering why Git is doing this and what we can do to fix it. We have researched it and found nothing.
The only proposed solution was using the command prompt with Git to use git add -u and add the files manually, but we'd need to add the folder design as well, not just individual files. We need to add the entire project and directory.
Any ideas?

checking ASP.net webAPI out using TFS with GIT into different directory causes missing directive or assembly reference errors

I had a ASP.net 4.5 webAPI that worked well that was located in C:\users\me\source\MyProject .
I then needed to push this project to a new Git Repo in Visual studio online.
to push it there I did the following
git remote add origin https://my-cool-webAPI.visualstudio.com/DefaultCollection/_git/MYcoolProject
git push -u origin --all
Everything appeared to be fine.
So i then cloned this project from the Visual Studio Online TFS Git repo to a new source directory.
It was in C:/users/me/source/MyProject and I moved it to C:\Users\me\Desktop\Source\MyProject
Now I have 166 errors and 166 warnings complaining about assembly references.
Here is more detail on a specific error.
Any idea what I did wrong?
** it looks like my references are out of wack, Notice it doesnt know the path to find Entity-Framework.
Is this because I didnt check in the Packages folder or something else
How do I refresh them? and How does one ensure they make it to source control, ie are they managed by a certain file similar to say a Rails Gemfile?
Currently I am doing the following steps to try and run my WebAPI that had no errors before I moved it to this new repo.
Clean the solution (that succeeds)
Build the solution (166 errors and 166 warnings)
Bateloche was on the money with his comments
In order to fix this I had to do the following.
I had to delete my packages folder.
Make sure your packages folder wasnt checked in by default its in the gitignore file that visual studio by defuault generates so it shouldnt be check in.
in VS goto Tools -> NuGet Package Manager -> settings and enabable Nuget to download missing packages.
Make sure to open the package manager console and click accept to refresh the nuget packages. The gotcha was that you may have to restart visual studio for this to work

Categories

Resources