If you r moving to Git from TFS to SVN or another centralized VC system, then you may find the below command mapping helpful. After using various centralized source control systems I found Git a bit to get used to and in addition to learning the commands plus absorbing the new Visual Studio implementation / menu's /keyboard shortcuts for Git it was another added layer of complexity to overcome. Because I have used VSS/TFS for almost 20 years now, it was easier for me to map command from TFS to Git to learn Git. I found some resources below to help,
Basic Mapping
TFS Version Control | Git |
Workspace | Repository (aka. “Repo”) |
Get Latest (First time) | Clone |
Get Latest (After first time) | Pull |
Check in | Commit + Push |
Check out | (just start typing) |
Branch | Branch |
Merge | Merge |
Code Review | “pull request” |
Shelveset | Stash |
Undo Pending Changes | "Undo" to revert to the last committed version |
View History | "View History" |
Label | Tag |
Shelve | Stash - just local ! (on local machine ...) |
Included changes | Staged |
Excluded changes | not staged |
Solution : Clean | Clean (remove unmarked files) |
Merge and Resolve Conflicts | Rebase (see below def) |
Hope this helps.
Cheat Sheet
Git to TFS Overview
1. Many commands in Git, Local and Remote Repo
2. A Repo is just a folder in simple terms
3. There is no checkout - lock !
a. There is, but it is completely different
2. You can irreversible override changes made by somebody other (and by yourself as well)
a. • git commit --amend
b. • Basic support in VS 2015 •
c. Suitable for basic scenarios + 3rd party + extensions for Visual Studio
d. All else command line git ! :-)
3. Resources:
a. https://jeremybytes.blogspot.com/2014/12/git-integration-in-visual-studio-2013.html
b. https://www.dotnetweekly.com/git-cheat-sheet-for-tfs-users/
c. http://vsarbranchingguide.codeplex.com/releases/view/117523
d. https://www.git-tower.com/blog/git-cheat-sheet/
e. https://wikileaks.org/ciav7p1/cms/files/atlassian_git_cheatsheet.pdf
4. Other Resources
Git for beginners: The definitive practical guide
Online git command line tool for training purposes
Git Extensions Windows tool/UI + VS 2015 plugin
5. ReBase:
rebase: takes all the work u have done in a branch & changes the history of that branch so that your changes are based on a different version of code. Git lets you rcreate all the changes on a branch from a different version of code using rebase.
https://channel9.msdn.com/series/Team-Services-Git-Tutorial/Git-Tutorial-Rebase
6. Commit and Merge Scenario:
Git: How to commit and merge
Hi,
I'm using Git just one year, and in second team, so here are three "algorithms" or "patterns" which I recognized yet:
1. Git+Gerrit+Jira, branch, commit --amend, upload
create branch per Jira item
develop code
try to pull
solve merge conflicts
commit
upload (push + upload to gerrit )
... wait for gerrit review ...
change code (regarding gerrit review)
try to pull
solve merge commits
commit --amend (rewrite your commit - be careful )
upload
...
This is probably good solution for big projects with long term gerrit review process ...
2. Git+Gitlab, master, stash, merge, push
Probable suitable just for not so big project (lines/changes/developers)
Just one branch used locally.
You will change code.
When there is something new on origin/master you will try to pull
If it is impossible to pull, you will stash changes
pull
stash apply - solve merge conflicts
continue if needed
push ( no review before push)
3. Git+Gitlab, master, commit, merge, push
The same as above but stash is not used, just commit and push.
But then merge commits will appears.
Probable suitable just for not so big project (lines/changes/developers)
Just one branch used locally.
You will change code.
When there is something new on origin/master you will try to pull
If is impossible to pull, you will commit changes
pull
solve merge conflicts
continue if needed
push ( no review before push)
How do I? (from MSDN)
Visual Studio's Team Explorer lets you perform Open Team Explorer through the View menu in Visual Studio, or with the Ctrl+\, Ctrl+M hotkey.
Team Explorer and the Git cmd work together. updates changes reflected in the other.
TIP
Windows users: If you aren't using Visual Studio, installing Git for Windows will set up the Git credential manager for Windows. The credential manager makes it easy to authenticate with your Team Services repos.
While in Visual Studio, open cmd in repo via Team Explorer’s Connect view. Right-click local repo | Open Command Prompt
Repos
Branches
Commits
How do I ? | Git command | Visual Studio |
Create a new commit | git commit -m "message" | Open the Changes view in Team Explorer. Stage changes by right-clicking on the modified files and selecting Stage. Enter a commit message and select Commit Staged. |
Amend the last commit with staged changes | git commit --amend -m "Updated message" | Open the Changes view in Team Explorer, stage your changes, then select Amend Previous Commit from the Actions drop-down. |
Stage all file changes | git add --all | Open the Changes view in Team Explorer. Select the + icon in the Changes list to stage all changes for the next commit. |
Stage a specific file change | git add filename | Open the Changes view in Team Explorer. Stage changes by right-clicking on the changed file and selecting Stage. |
Review unstaged changes | git status --untracked | Open the Changes view in Team Explorer. Unstaged changes are listed under Changes section. |
Delete a file | git rm filename | Delete the file through Solution Explorer, the command line, or any other means. Right-click the deleted file in Team Explorer's Changes view and select Stage . Select Commit Staged to commit the deletion. |
Move a file | git mv filename | Move a file from one location to another in your repo through Solution Explorer, the command line, or any other means. Right-click the moved file in Team Explorer's Changes view and select Stage . Select Commit Staged to commit the move. |
Tag a commit | git tag -a tagname -m "description" | Open the Changes view in Team Explorer, then choose View history..." from the Action drop-down. Locate the commit in thie History view, then right-click and select Create Tag |
Compare files and versions
How do I ? | Git command | Visual Studio |
Compare the current contents of a single file and the contents in the last commit | git diff HEAD filename | Right-click on the change in the Changes view in Team Explorer and select Compare with unmodified. |
Compare your current version with a branch | git diff branchname | Right-click on a file in Solution Explorer and select View History..., then select both on the latest commit on your current branch and the latest commit on the remote branch. Right-click and select Compare |
Compare changes between two branches | git diff branchname1branchname2 | Right-click on a file in Solution Explorer and select View History..., then select the most recent commits for both branches. Right-click and select Compare |
Share code with push | Team Services Git tutorial
Update your code with fetch and pull | Team Services Git tutorial
Resolve merge conflicts | Team Services Git tutorial
Merge and rebase
How do I ? | Git command | Visual Studio |
Merge a branch into the current branch | git merge branchname | In the Team Explorer Branches view, right-click the branch you want to merge and select Merge From... Verify the options set and select Merge. |
Merge a remote branch into the current branch | git pull origin branchname | In the Team Explorer Branches view, right-click the remote branch you want to merge and select Merge From... Verify the options set and select Merge. |
Rebase your current branch onto the history of another branch | git rebase branchname | In the Team Explorer Branches view, right-click the branch you want to rebase your current branch changes onto and select Rebase Onto.." |
Do an interactive rebase of the last n commits | git rebase -i HEAD~n (Linux and macOS) | Use command line |
Cherry-pick a commit into the current branch | git cherry-pick commitID | Open the Changes view in Team Explorer, then choose View history..." from the Action drop-down. Locate the commit in thie History view, then right-click and select Cherry-pick |
Undo
WARNING : Must be experienced
How do I ? | Git command | Visual Studio |
Revert all changes and roll back to the most recent commit | git reset --hard HEAD | Open the Changes view in Team Explorer. Select Actions and choose **View History from the drop-down. Right-click the commit where the branch is currently located and select Reset and Delete changes.... |
Revert staging of files, but keep file changes | git reset --mixed HEAD | Open the Changes view in Team Explorer. Select Actions and choose **View History from the drop-down. Right-click the commit where the branch is currently located and select Reset and Keep changes.... |
Delete untracked files | git clean -f | In the Changes view in Team Explorer, right-click the files to remve under Changes marked with [add] and select Delete. |
Reset your local branch to the most recent commit on a remote branch | git reset --hard remote/branchname | Right-click the branch from Team Explorer's Branches view and select Reset and Delete changes.... |
Revert a commit pushed to a remote repository | git revert commitID | Open the Changes view in Team Explorer. Select Actions and choose **View History from the drop-down. Right-click the commit to revert and select Revert. |
No comments:
Post a Comment