Actions

Difference between revisions of "Git"

From zen2

(Git With Android Studio)
 
(10 intermediate revisions by the same user not shown)
Line 22: Line 22:
  
 
*git filter-branch --index-filter 'git update-index --remove myConfigFile' HEAD
 
*git filter-branch --index-filter 'git update-index --remove myConfigFile' HEAD
 +
 +
==Merge branches==
 +
Quickest way:
 +
<pre>
 +
git checkout master
 +
git pull origin master
 +
git merge test
 +
git push origin master
 +
</pre>
 +
 +
==Undo a commit==
 +
<pre>
 +
git commit -m "Something terribly misguided"           
 +
git reset HEAD~ 
 +
</pre>                                       
 +
Edit files as necessary
 +
<pre>                     
 +
git add .                                     
 +
git commit -c ORIG_HEAD 
 +
</pre>
 +
 +
 +
To restore everything back to the way it was prior to the last commit, we need to reset to the commit before HEAD:
 +
<pre>
 +
git reset --soft HEAD^    # use --soft if you want to keep your changes
 +
git reset --hard HEAD^    # use --hard if you don't care about keeping the changes you made
 +
</pre>
 +
 +
=Git Ignore=
 +
Go to gitignore.io to generate a good list of files to ignore
 +
 +
eg Search Android Studio and copy resulting to .gitignore
 +
 +
=Git With Android Studio=
 +
https://youtu.be/vS39tcSKBHc
 +
*Create the project + repo on Bitbucket. Create the project with Android Studio.
 +
*In AndroidStudio,
 +
**choose VCS|Enable Version Control Integration, choose git
 +
**in the Project tree (left panel), change view to Project, and locate .gitignore file. Update with gitignore from Git Ignore above
 +
*On Bitbucket website,
 +
**navigate to the repo. On the Overview page choose Get started with command line|I have an existing project
 +
**copy "git remote add origin https://xxxx@bitbucket.org/xxxx/xxxx.git"
 +
*In Android Studio,
 +
**open Terminal panel
 +
***check you are in the project's root directory
 +
***paste in the command copied from bitbucket
 +
***git add .
 +
**Click the VCS push button (ctrl-K) to do initial commit. On the Commit button choose Commit and Push. Take obvious options, disregard code review.

Latest revision as of 21:43, 20 November 2017

Add changes and upload to repo

  • git add -u
  • git add .
  • git status
  • git commit -m "A description of changes"
  • git push

Pull from repo

  • git pull


Remove from git

eg p/w file

  • git rm myConfigFile
  • echo myConfigFile > .gitignore
  • git add .gitignore
  • git commit -m "from now on, no more myConfigFile"

The other extreme approach (dangerous especially if you have already pushed your repo to a remote one) would be to entirely remove that file from the history of said repo:

  • git filter-branch --index-filter 'git update-index --remove myConfigFile' HEAD

Merge branches

Quickest way:

git checkout master
git pull origin master
git merge test
git push origin master

Undo a commit

git commit -m "Something terribly misguided"             
git reset HEAD~   

Edit files as necessary

                      
git add .                                       
git commit -c ORIG_HEAD  


To restore everything back to the way it was prior to the last commit, we need to reset to the commit before HEAD:

git reset --soft HEAD^     # use --soft if you want to keep your changes
git reset --hard HEAD^     # use --hard if you don't care about keeping the changes you made

Git Ignore

Go to gitignore.io to generate a good list of files to ignore

eg Search Android Studio and copy resulting to .gitignore

Git With Android Studio

https://youtu.be/vS39tcSKBHc

  • Create the project + repo on Bitbucket. Create the project with Android Studio.
  • In AndroidStudio,
    • choose VCS|Enable Version Control Integration, choose git
    • in the Project tree (left panel), change view to Project, and locate .gitignore file. Update with gitignore from Git Ignore above
  • On Bitbucket website,
  • In Android Studio,
    • open Terminal panel
      • check you are in the project's root directory
      • paste in the command copied from bitbucket
      • git add .
    • Click the VCS push button (ctrl-K) to do initial commit. On the Commit button choose Commit and Push. Take obvious options, disregard code review.