Wednesday, June 30, 2021

GIT

GIT


Git Quick Reference 
Getting help:  

git help command  
or  
git command --help  
Show help for a command  
repo pr -b engsys -t "platformtoolset removed in vcxprojects and added build.props"

Repository creation:  

git init  
Create a repository in the current directory  
git clone url  
Clone a remote repository into a sub directory  
File operations:  

git add path  
Add file or files in directory recursively  
git rm path  
Remove file or directory from the working tree  
      -f  
Force deletion of file(s) from disk  
git mv path destination  
Move file or directory to new location  
      -f  
Overwrite existing destination files  
git checkout [rev] file  
Restore file from current branch or revision  
      -f  
Overwrite uncommitted local changes  
Working tree:  

git status  
Show status of the working tree  
git diff [path]  
Show diff of changes in the working tree (only unstaged??) 
git diff HEAD path  
Show diff of stages and unstaged changes  
git add path  
Stage file for commit  
git reset HEAD path  
Unstage file for commit  
git commit  
Commit files that has been staged (with git-add)  
      -a  
Automatically stage all modified files  
git reset --soft HEAD~1 
Undo commit & keep changes in the working tree  
git reset --hard HEAD~1 
Reset the working tree to the last commit  
git clean  
Clean unknown files from the working tree  
Examining History:  
Git  
git log [path]  
View commit log, optionally for specific path  
git log [from[..to]]  
View commit log for a given revision range  
      --stat  
List diffstat for each revision  
      -S'pattern'  
Search history for changes matching pattern  
git blame [file]  
Show file annotated with line modifications  
Remote repositories - remotes 

git fetch [remote]  
Fetch changes from a remote repository  
git pull [remote]  

Fetch and merge changes from a remote repository  

git push [remote]  
Push changes to a remote repository  
git remote  
List remote repositories  
git remote add remote url  
Add remote to list of tracked repositories  
Branches:  

git checkout branch  
Switch working tree to branch  
      -b branch  
Create branch before switching to it  
git branch  
List local branches  
git branch -f branch rev  
Overwrite existing branch, start from revision  
git merge branch  
Merge changes from branch  
Exporting and importing:  

git apply - < file  
Apply patch from stdin  
git format-patch from[..to]  
Format a patch with log message and diffstat  
git archive rev > file  
Export snapshot of revision to file  
      --prefix=dir 
Nest all files in the snapshot in directory  
      --format=[tar|zip]  
Specify archive format to use: tar or zip  
Tags:  

git tag name [revision]  
Create tag for a given revision  
      -s  
Sign tag with your private key using GPG  
      -l [pattern]  
List tags, optionally matching pattern  
File status flags:  

M modified  
File has been modified  
C copy-edit  
File has been copied and modified  
R rename-edit  
File has been renamed and modified  
A added  
File has been added  
D deleted  
File has been deleted  
U unmerged  



Resolve merge conflict using below command: 

git merge remotes/origin/engsys 


git pull <branch name>  
git merge <branch name>  

i.e. remotes/origin/engsys 



Detailed steps are at the OneBranch Home (Get Started > Enlist in Existing Repo), below are the excerpted and customized steps: 

  1. Get Access (if first time): 
      • 19411 
    • May take up to 24 hours on Approval/Renewal for permission to propagate 

    Install Prerequisites (if first time): 
    1. Open an elevated command line or elevated PowerShell. 
    2. If you've older version of chocolatey or git installed in the machine, please uninstall them before proceeding further. 
    3. Run the command: 
    4. Reopen a new admin command prompt. 
    5. Install/Upgrade Git (use latest version) 

  1. Initialize Working Directory (if first time): 
    1. Create a directory that you want to use as your working directory (e.g. "md d:\one"). 
    2. Change into that directory (e.g. "cd /d d:\one"). 
    3. Initialize that directory with the Azure Manifest by running the following command literally from admin command prompt: 
    4. Enter the email address or phone number for the account you want to sign in with." i.e. [alias]@microsoft.com. 

    1. Use a 64-bit admin command prompt (or create one): 
      1. Right-click on your command prompt icon > Properties > Shortcut > Target should have "%windir%\system32\cmd.exe". 
      2. Right-click on your command prompt icon > Run as Administrator. 

    2. Navigate to your initialized working directory (e.g. "cd d:\one") 

    1. Run the "repo sync <Repo Name>" command:repo sync 
      1. Note, do not run "repo sync" without any argument. This would sync all Azure repositories which may take days if not weeks.​ 
      2. ​​To sync with ​a specific repository <Repo Name>: 
        repo sync <Repo Name> 
      3. E.g. to sync repo "git" run: 
        repo sync SystemCenter-Migration-SCOM 

    2. ​​​When repo sync completes, cd to the repo's directory and run repo env to get a CoreXT command prompt for that repo. 
      1. Look out for a prompt for user to specify the package cache folder, e.g. d:\cxcache, if it is not set already 
      2. E.g. to get CoreXT a command prompt for SystemCenter-Migration-SCOM: 
        cd d:\one\SystemCenter\Migration\SCOM 
      repo env 
    3. Optionally, you can create a shortcut for a repo on your desktop (be sure to set "Run as administrator" in Properties > Advanced…) 
      cd d:\one\SystemCenter\Migration\SCOM 

      repo env --shortcut 

  1. Checkout the right branch 
    1. The above steps will enlist you in the "master" branch of the repo, which doesn't have much of git the content (you can verify this with "git branch"), but in most cases you will be working in a "features/*" branch off of the "develop" branch.  See Branching guidelines.  Find out the right branch to enlist in from your lead. 
    2. In the admin command prompt for your repo (see "repo env" above), run: 
      git checkout <branchname> 
    3. Sync to your branch: 
      git pull 
    4. All engsys tasks will be done 'engsys' branch 
    5. After checking-out new branch, close the corext window and start new window or run a init no_cache command 
  


For additional repos, repeat steps 4 & 5 


No comments:

Post a Comment