![]() Here one thing is very important to remember that amending the last commit rewrites the commit history. If you just added some files or fixed a bug but don’t want to add another commit message then you can use following git command with -no-edit flag. git commit -amend -m "your-new-commit-message" Then you can use the following git command. You just added a commit message and realized that there is a typo in your commit or you just want to make your commit message more expressive and understandable. You want to develop a feature from this detached head state then you have to make a branch from this state and develop your feature there. But when head points to a commit, but not a branch then it goes to a detached head state. When Head points to a branch, git doesn’t complain. Generally, Head in git can point to a branch or a commit. Head is simply a reference to the current commit (latest) on the current branch. This will fall in detached head state in git. You can use shorthand commit id safely if your project isn’t very large. You have a branch name development and you want to make a branch from development and switch to your new branch directly. If you don’t stash or commit those changes, it will also reflect in your switched branch which you may not want or need. If you already changed some file in your current branch, then be sure to stash your changes or commit the changes. ![]() Then you can just run the following command. You will get your changes in your desired branch. Then you can stash your changes and checkout to your desired branch and run git stash pop there. If you don’t want those changes back then you have to run the following command. If you want your changes back then you have to run the following command. Now, you want to just see the output or code of that branch before you made those changes. You are working in a branch and made some changes. git log -author="John Doe" # Scenario with stash I am assuming the author name is John Doe. If you want to see the commit message of a specific author, then you can run the following command. The commit id is shorthand because the full commit id is forty hexadecimal characters that specify a 160-bit SHA-1 hash. The first seven character in above output is the shorthand commit id and then we have our commit message. Git log -oneline will show the following kind of output. This shows a lot of information but you just need to see commit id and message. You want to see your commit history so you just ran a git log command. You want to push your local branch code but your local branch name doesn’t match with the name of remote repository branch name. You need to delete the old branch from the remote and push up the new one. If you’ve already pushed the branch with old name, then there are a couple of extra steps required. You want to change the current branch name, then you can just run the following command. You have made a typo in your branch name or you want to change your branch name, then the following command will change your branch name. You want to delete files from git repository but not from your file system then you can run this command. If your file is in staging area then you have to give additional force flag. You can delete your tracked file using this command. Now you want to delete your tracked files. If you want to see which untracked files will be removed before removing then you can run this command. This command will delete all files and directories that are not tracked by git. To make your working tree clean you can run the following command. Untracked files are those which you didn’t add already using git add After some time you realized that you don’t want those files or folders. You created some new files or folders in your branch. git add models/\*.py # Scenario with clean The following command will add all python files from sub directories of models/ directory. You want to add files with specific extension and also want to specify directory name then you can run the following command. Following command will add all python files. to include all files with that extension. Of course you can add all the files one by one. You just want to add files with specific extension in your staging area. “closeup photo of eyeglasses” by Kevin Ku on Unsplash # Scenario with add
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |