-
-
Save bablukpik/2ea2310a9aac63cac49de8b0c38119b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Head: | |
HEAD is a ref (reference) to the currently checked out commit. In normal states, it's actually a symbolic ref to the branch you have checked out. | |
//01// Rollback Using git Reset: | |
->If you want to fix up your latest commit, you can undo the commit, and unstage the files in it, by doing: | |
->If you want to uncommit N commits, but keep the code changes in your working directory: | |
git reset HEAD~N | |
->If we want to delete commit but file will be not changed | |
git reset --soft commit_hash | |
->If we want to delete commit with changed | |
git reset --hard commit_hash | |
->If you want to get rid of your latest commit, and do not want to keep the code changes, you can do a "hard" reset. | |
git reset --hard HEAD~1 | |
->To rollback to a specific commit: | |
git reset --hard commit_sha | |
->To rollback 10 commits back: | |
git reset --hard HEAD~10 | |
->If you don't want to keep your changes that you made: | |
git reset --hard HEAD^ | |
->It will delete the named reference HEAD | |
git update-ref -d HEADgit restore a deleted file after merge | |
->git restore a deleted file after merge | |
git checkout HEAD -- module/FormDependencies/src/FormDependencies/Entity/LanguageList.php | |
->Delete the file in master | |
git rm test.txt | |
->After the bad merge you can undo, and then re-merge, but add back the file: | |
git checkout HEAD@{1} . | |
git merge --no-commit master | |
git checkout master test.txt | |
git add test.txt | |
git commit | |
//02// Rollback Using git Checkout: | |
git checkout master | |
->Return to the master branch. It is also a way to get back to the “current” state of the project | |
git checkout <commit> <file> | |
->Check out a previous version of a file | |
git checkout <commit> | |
->All files will be updated using the specified commit in the working directory.This will put you in a detached HEAD state. | |
git checkout [revision] . | |
git checkout fd6cb176297acca4dbc69d15d6b7f78a2463482f . | |
git checkout master | |
git checkout a1e8fb5 hello.py | |
->If you decide you don’t want to keep the old version, you can check out the most recent version with the following: | |
git checkout HEAD hello.py | |
//03// Rollback Using git Revert and git Back: | |
git revert Is Better Than git checkout: | |
->If you want to keep the history | |
git revert | |
->Remove the latest commit: | |
git back | |
->Remove the latest three commits: | |
git back 3 | |
//04//GIT Branching (Basic): | |
->The git branch command lets you create, list, rename, and delete branches. | |
->By default We work on Master Branch (Released project). It will be good think if we work on temporary branch. When it will be stable we will move the stable code on the master branch as final project. | |
->For new Branch creating: | |
git branch develop | |
->For branch checking: | |
git branch | |
->For moving on new branch: | |
git checkout develop | |
->For merged new branch's commit history or snapshots with master branch: | |
git merge develop master | |
->For deleting a branch: | |
git branch –d develop | |
->Rename the current branch to <branch>. | |
git branch -m <branch> | |
-> copy one branch's (i.e. master branch) all commits to a new one branch | |
git checkout existingbranch | |
git merge master | |
git checkout master | |
git reset --hard HEAD~3 # Go back 3 commits. You will lose last 3 commits work. | |
git checkout existingbranch | |
->How to see 'Detached HEAD' commits | |
git reflog or gitreflog --all or git log -p | |
->How to get 'Detached HEAD' commits back into a Branch | |
git merge HEAD@{1} | |
//05// Working Together | |
Joe (Person 01): | |
-> All folder will show | |
ls | |
-> Suppose we want to go Desktop folder | |
cd desktop | |
->move to joe folder | |
cd joe | |
-> For download the project for working to the specific location (joe folder). | |
git clone repository_url | |
Now, create a php/html file to the project folder: | |
-> The file or working directory is checked up to date or not? or the file is git staged or not? | |
git status | |
-> For file git staged or up to date | |
git add . or git add file_name.html or git add –A | |
-> check again | |
git status | |
-> What is the reason to change the file | |
git commit –m `I changed or staged or added file name` | |
-> The file is ready to be uploaded or imported to the centralized location or project repository. | |
git push | |
Now, refresh the centralized location to view the update or change | |
Suppose Sarah (2nd person) have been updated the file here we will see the difference between the two files | |
-> To get the updated file from server that was changed by Sarah. | |
git pull | |
-> Now Joe has changed something to the file | |
git add –A | |
-> For uploaded the changed file. | |
git push | |
Sarah ( 2nd Person): | |
Same process | |
But there can have a conflict error. | |
Conflict Error: When push command is given at the same time from different ends without pull command. | |
How to solve... | |
git status | |
->Pull the project from server to local development machine | |
git pull | |
-> See the file and remove the conflict lines and save it and then commit | |
git add –A | |
git commit –m `commit something` | |
git push | |
//06// type git then hit enter then it will show all of the git commands | |
//07// In Details of Checkout | |
git status | |
->We can see the difference between previous version and current version of the file. | |
git diff testFolder01/file01.txt | |
->For specific folder staging | |
git add testFolder01/ | |
->For taking a snapshot/commit/saving | |
git commit –am ‘Something has changed’ | |
git status | |
->We want to get the version | |
git checkout commit_code – testFolder01/test01.txt | |
->It will return green color that means the file has been retrieved | |
git status | |
->For seen the changed code | |
git diff –staged testFolder01/test01.txt | |
git commit –m ‘Reverting test01.txt file’ | |
->For checking the status of working directory clean | |
git status | |
///GIT Shortcut Options Meaning/// | |
[-p|--patch] | |
[-q|--quiet] | |
[-m|--message <message>] | |
[-u|--include-untracked] | |
[-a|--all] | |
-R //most recent | |
force (-f) | |
[-a|--all] | |
[-g|--guide] | |
[-i|--info] | |
[-m|--man] | |
[-w|--web] | |
[-p|--paginate] | |
[--version] | |
-s | |
--short | |
-b | |
--branch | |
-v | |
--verbose | |
-u[<mode>] | |
--untracked-files[=<mode>] | |
--ignored | |
[-s <strategy>] | |
--edit (or -e) | |
--no-edit | |
--commit | |
--no-commit | |
git merge --abort | |
-q | |
--quiet | |
-v | |
--verbose | |
--log | |
///Temporary Saving | |
->You can save your untract/modified files without commit in stack (stash) | |
git stash | |
->To restore them type "git stash apply" | |
git stash apply | |
git stash unapply | |
git stash-unapply | |
git stash list | |
git stash drop | |
git stash pop | |
git stash show -p | |
git stash show -p stash@{0} | git apply -R | |
git stash branch | |
///Replace last commit to new commit:- | |
->It will replace last commit to new commit. | |
git commit --amend -m "message" | |
git commit -a -m "" or git commit -am "" | |
///Unknown files deleting | |
->Clean unknown files from the working tree | |
git clean | |
->You can undo or unstaged files from staged | |
git rm --cached | |
->This is the differece between modified and unmodified file | |
///git diff HEAD | |
/// | |
->which will bring up your editor | |
git commit --amend | |
or | |
->which will allow you to specify the new message on the command line | |
git commit --amend -m "Your new message here" | |
///To see the specific file history | |
git log -p filename | |
gitk [filename] | |
gitk --follow [filename] | |
git show | |
git show head | |
git show comm_hash | |
/// | |
->To show what revision and author last modified each line of a file: | |
git blame filename | |
->or if you want to use the powerful blame GUI: | |
git gui blame filename | |
// | |
Server update: | |
-> ssh [email protected] | |
->ls /var/www/html/ | |
-> cd ../ | |
-> cd / | |
-> cd root | |
-> touch test.txt | |
-> cd www/html | |
-> git reset --hard | |
-> rm test.txt | |
-> git ls | |
-> git status | |
-> git fetch | |
-> git remote | |
-> git remote remove origin | |
-> git remote | |
-> git remote add origin https://[email protected]/jacosit/formatconversionv2.git | |
-> git pull -u origin master | |
-> git log | |
-> git pull | |
Database Edit: | |
-> mysql --version; | |
-> mysql -u convert-tool -p -h 10.128.10.10 | |
-> show databases; | |
-> use convert-tool; | |
-> show tables; | |
-> select * from buyer; | |
// | |
git fetch origin master | |
git merge master | |
git push origin development:master | |
git checkout master | |
git pull origin master | |
git merge test | |
git push origin master | |
git checkout master | |
git merge origin/master --allow-unrelated-histories | |
//Untracked files removed | |
git clean -d -x -f | |
will remove untracked files, including directories (-d) and files ignored by git (-x). Replace the -f argument with -n to perform a dry-run or -i for interactive mode and it will tell you what will be removed. | |
folder remove: | |
git clean -f '.idea/' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment