1. Remove Files
Step 1. Switch to your branch
Strp 2. Remove files using -rm command
Ex : git rm -r sites/all/modules/stage_file_proxy
Step 3. Add this file to the .gitignore
2. Resolve a conflict
#Quickly Resolve conflict
grep -lr '<<<<<<<' . #Find conflicted files
git checkout --ours PATH/FILE #use my file
git checkout --theirs PATH/FILE #use the remotr/other file
grep -lr '<<<<<<<' . | xargs git checkout --ours
grep -lr '<<<<<<<' . | xargs git checkout --theirs
Get a file from Head
git checkout HEAD PATH/TO/FILE
git checkout PATH/TO/FILE
3.Other Solutions
1. Ignore all local changes and get from frmote master
git checkout path/to/file.ext
2.
4. Find the most recent commits and Files
To see last commits
git log
To see the different
​git show THE_COMMIT_ID
To get the modified files list
​git show --name-only THE_COMMIT_ID
5. Undo git add
(to remove from 'add', to correct faultly added files)
git reset THE_FILE_NAME
6. Revert Last commit and pull
#Revert last Commit(s)
git reset HEAD^ ;Last commit
git reset HEAD^N ;Last N commit (N = int)
git reset HEAD^^ = git reset HEAD^2, git reset HEAD^^^ = git reset HEAD^3
#Revert last pull
git reset HEAD@{1}
# Revert a commit
1. Get the commit hash using 'git log
'
2. git revert <commit hash>
#Git Remove all local changes and pull
git reset --hard origin/master
git pull origin master
#Git Remove all local changes of a file and get from remote
git checkout path/to/file.txt
7. Delete a branch /!\ CAUTION
#Local
git branch -d the_local_branch
#Remote
git push origin :the_remote_branch
8.Rename a branch
Rename Any branch
git branch -m <oldname> <newname>
Rename the current branch
git branch -m <newname>
To reset Found and Reset git commands
git reflog #To get the list
git reset HEAD@{1} #To reset to this version
git reset aabbccdd #To reset to this version
To save changes:
git stash #To save changes
git stash pop #To get saved changes
To get selected commits, or isolate some commits:
#1.Create new branche
git cherry-pick <the_commit_number Ex: aa4e310086272a7892143dabcdac26b163625dbf>
#Commit and push the new branch
Force a PULL
git push -f origin yourbranch
Move from A source branch to another source Branche
(For example, When you must start [create new branche] from maser
but you are started from develop
)
Methode 1:
1. Go to the badly started branche (git checkout NEW_BAD
)
2 Reset last commits (git reser HEAD^
)
3 Save changes using stash (git stash
)
4 Go to the MASTER branche (git checkout MASTER
)
5 Create a new branche from MASTER (git checkout -b NEW_FROM_MASTER
)
6 Re load saved changes from stash (git stash pop
)
7 Add, Commit and Push your changes (git commit -am 'comment'
)
Methode 2.
1. Go to the badly started branche (git checkout NEW_BAD
)
2 Get the commit number/numbers like aa4e310086272a7892143dabcdac26b163625dbf
(git log
)4 Go to the MASTER branche (git checkout MASTER
)
3 Go to the MASTER branche (git checkout MASTER
)
5 Create a new branche from MASTER (git checkout -b NEW_FROM_MASTER
)
6 Load your commits using cherry-pick
(git cherry-pick <the_commit_number Ex: aa4e310086272a7892143dabcdac26b163625dbf>
)
7 Add, Commit and Push your changes (git commit -am 'comment'
)
Resolve a git merge conflict in from remote/origin
git pull -X theirs
.
Comments